-
-
Save cemerick/71a50c1628d856d3a74d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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