morph's incomplete because it extends Functor only for collections and function composition; I'll add String and boxed types, but for now Long's extension must be supplied: (use 'blancas.morph.core) (extend-type java.lang.Long Functor (fun [this f] (f this)))
With this, it's like alto.generic but fmap comes curried: user=> (fmap inc {:a 3 :b 9 :c 16}) {:a 4, :c 17, :b 10} user=> (fmap (fmap inc) {:a {:b 9 :c 16} :d 25}) {:a {:c 17, :b 10}, :d 26} For use with arbitrarily nested maps something like this is needed: (defn f [k] (fn g [x] (if (map? x) (fmap g x) (k x)))) user=> (fmap (f inc) {:a {:b 9 :c {:x 16 :y 20}} :d 25}) {:a {:c {:y 21, :x 17}, :b 10}, :d 26} On Friday, July 26, 2013 9:31:41 PM UTC-7, Ben wrote: > > On Fri, Jul 26, 2013 at 9:27 PM, Yoshinori Kohyama > <yyko...@gmail.com<javascript:> > > wrote: > >> Thank you, Ben. >> >> If I think the map as a tree, then as a functor, what I do is 'fmap' (in >> Haskell or some languages), >> ,as you say. >> Thanks for saying that. >> >> Does Algo supply things around Functor, Applicative and Monad? >> I'm going to look at Algo. >> >> Or anybody knows any other libraries or implementations around these >> things in Clojure? >> >> > algo.generic has a functor implementation for regular maps which you could > already use, if your maps have uniform depth: > > (fmap (partial fmap inc) {:a {:x 1} :b {:y 2}}) ---> {:a {:x 2} :b {:y 3}} > > if you want to use that fmap (or, I'd think, the fmaps provided by either > morph or fluokitten) with uneven depths, you'd have to wrap them in a > defrecord or deftype, I'd expect. > > -- > Ben Wolfson > "Human kind has used its intelligence to vary the flavour of drinks, which > may be sweet, aromatic, fermented or spirit-based. ... Family and social > life also offer numerous other occasions to consume drinks for pleasure." > [Larousse, "Drink" entry] > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.