我对 Clojure 非常陌生,通过阅读优秀的开源代码来学习 Clojure。所以我选择了 Ring 并开始阅读代码,但卡在了 assoc-query-params 函数中。(位于ring.middleware/params.clj)
而且我不明白为什么要使用“合并”。谁能帮我理解这段代码片段?
(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 {}})))