Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created July 29, 2010 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cemerick/71a50c1628d856d3a74d to your computer and use it in GitHub Desktop.
Save cemerick/71a50c1628d856d3a74d to your computer and use it in GitHub Desktop.
; not a great name, but....
(defn kw-map-fn
[f]
(fn [& args]
(if (-> args last map?)
(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