如何交换!和mmap函数在这里工作?

时间:2017-04-01 19:23:29

标签: clojure clojurescript

这是Reagent project的摘录。查看complete-allclear-done,我理解重点是更换已修改的地图。我不明白它是如何完成的。 mmap的定义需要3个参数 - 而complete-all似乎是用两个调用它,即map#(assoc-in % [1 :done] v)。使用clear-doneremove进行#(get-in % [1 :done])次来电。我尝试使用repl进行实验,但无法让requires得以解决。

   (ns todomvc.core
      (:require [reagent.core :as r]))

    (defonce todos (r/atom (sorted-map)))

    (defonce counter (r/atom 0))

    (defn add-todo [text]
      (let [id (swap! counter inc)]
        (swap! todos assoc id {:id id :title text :done false})))

    (defn toggle [id] (swap! todos update-in [id :done] not))
    (defn save [id title] (swap! todos assoc-in [id :title] title))
    (defn delete [id] (swap! todos dissoc id))

    (defn mmap [m f a] (->> m (f a) (into (empty m))))
    (defn complete-all [v] (swap! todos mmap map #(assoc-in % [1 :done] v)))
    (defn clear-done [] (swap! todos mmap remove #(get-in % [1 :done])))

1 个答案:

答案 0 :(得分:-2)

现有地图作为函数的第一个参数传递。当一切都失败了......