Tuesday, 20 August 2013

Why merge-with is used instead of simple 'merge' in Ring, Clojure?

Why merge-with is used instead of simple 'merge' in Ring, Clojure?

I'm very new to Clojure and learning Clojure by reading good open source
code. So I choose Ring and starting to read the code but got stuck in
assoc-query-params function. (which is located in
ring.middleware/params.clj)
And I could not understand why "merge-with" is used. Can anybody help me
to understand this code snippet?
(defn- assoc-query-params
"Parse and assoc parameters from the query string with the request."
[request encoding]
; I think (merge request (some-form)) is enough
; but the author used merge-with with merge function.
(merge-with merge request
(if-let [query-string (:query-string request)]
(let [params (parse-params query-string encoding)]
{:query-params params, :params params})
{:query-params {}, :params {}})))

No comments:

Post a Comment