Maybe in clojure -


trying write composed function in clojure exits @ first nil value, (e.g you'd chaining maybes in haskell) following:

(defn wrap [f] (fn [x] (if (nil? x) nil (f x))))  (defn maybe [arg & functs] ( (comp (reverse (map wrap functs))) arg)) 

so i'd get, e.g.

(defn f1 [x] (+ x 1))  (maybe 1 f1 f1 ) => 3  (maybe nil f1 f1) => nil 

which unfortunately giving me this: classcastexception clojure.lang.persistentlist cannot cast clojure.lang.ifn user/maybe (no_source_file:1)

can provide on i'm doing wrong here? what's idiomatic way this?

the idiomatic way use some->. see the documentation of macro more details.

don't let stop making own, of course!


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -