Skip to content

Instantly share code, notes, and snippets.

@raek
Forked from cemerick/kw_map_fn.clj
Created July 29, 2010 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raek/96d7618e294c5278c90f to your computer and use it in GitHub Desktop.
Save raek/96d7618e294c5278c90f to your computer and use it in GitHub Desktop.
; not a great name, but....
(defn kw-map-fn
[f]
(fn [& args]
(if (-> args count odd?)
(apply f (concat (drop-last args)
(mapcat identity (last args))))
(apply f args))))
(defn foo [& {:keys [a]}] (println a))
(def foo (kw-map-fn foo))
(defn bar [& {:keys [a] :as m}] (foo m))
(def bar (kw-map-fn bar))
1:15 user=> (foo :a 5)
5
nil
1:16 user=> (foo {:a 5})
5
nil
1:17 user=> (bar :a 5)
5
nil
1:18 user=> (bar {:a 5})
5
nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment