Without each type specifying where it would like the function applied the result will be sort of hacky, but here's my hackey attempt at fmap in clojure.
It makes some assumptions (e.g. you would only want to apply f to the values rather than the keys of a hash). Also I'm not sure what the best way is to check is a symbol is a function in Clojure. user> (defn fmap [f arg] (cond (or (fn? arg) (= (class arg) clojure.lang.MultiFn)) (comp f arg) (list? arg) (map (partial fmap f) arg) (vector? arg) (vector (map (partial fmap f) arg)) (map? arg) (apply hash-map (mapcat (fn [[k v]] [k (fmap f v)]) arg)) true (f arg))) #'user/fmap user> ((fmap (partial + 1) sqrt) 9) 4 user> (fmap (partial + 1) (list 1 {:a 2 :b 3} 4)) (2 {:a 3, :b 4} 5) user> -- 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