On Fri, Jul 26, 2013 at 9:31 PM, Ben Wolfson <[email protected]> wrote:
> On Fri, Jul 26, 2013 at 9:27 PM, Yoshinori Kohyama <[email protected]>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. > > You could also engage in this underhanded trick: user=> (defmethod f/fmap Object [f v] (f v)) ;;; "Identity" functor #<MultiFn clojure.lang.MultiFn@5de33e> user=> (defmethod f/fmap clojure.lang.IPersistentMap [f v] (into {} (map (fn [[k v]] [k (f/fmap f v)]) v))) #<MultiFn clojure.lang.MultiFn@5de33e> user=> (f/fmap inc {:a {:y 1} :b {:x 2 :z {:c [1 2 3]}}}) {:a {:y 2}, :b {:z {:c [2 3 4]}, :x 3}} But I wouldn't recommend it. -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
