/ Published in: Clojure
A nice function which creates a list of function that can be applied during a map.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
; creating a list of functions from fns (defn juxt [& fns] (fn[ & arg] (map #(apply % args) fns))) ; a simple map (def test-map {:a "1" :b "2" :c "3" :d "4"}) ; applying two functions at once which results with ("1" "3") ((juxt :a :c) test-map) ; applying both identity & square on the range values, ; result with ((1 1) (2 4) (3 9) (4 16) (5 25)) ((partial map (juxt identity #(* % %))) (range 1 6))
URL: http://groups.google.com/group/clojure/browse_thread/thread/c960ec89bd0a85ac