-
-
Save raek/96d7618e294c5278c90f 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 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