Skip to content

Instantly share code, notes, and snippets.

@glenjamin
Created March 19, 2013 21:55
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 glenjamin/5200480 to your computer and use it in GitHub Desktop.
Save glenjamin/5200480 to your computer and use it in GitHub Desktop.
Helpful function for dealing with ring request maps?
(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