Created
March 19, 2013 21:55
-
-
Save glenjamin/5200480 to your computer and use it in GitHub Desktop.
Helpful function for dealing with ring request maps?
This file contains hidden or 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
(defn ->merge [m & fns] | |
"Merge the recursive result of calling f on m into m | |
Useful when dealing with operations on ring request maps" | |
(loop [m m | |
fns fns] | |
(if-not (seq fns) | |
m | |
(recur (merge m ((first fns) m)) (rest fns))))) | |
(assert (= {:a 1 :b 2} | |
(->merge {:a 1} (fn [m] {:b 2})))) | |
(assert (= {:a 1 :b 2 :k #{:a :b}} | |
(->merge {:a 1} (fn [m] {:b 2}) (fn [m] {:k (set (keys m))})))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment