循环遍历一系列惰性地图并更改其中一个地图中的一个值

cycle through a lazy sequence of maps and change one of the values in one of the maps

我有一些地图的惰性序列。
我想循环浏览每张地图并执行:
if (= :b "this one") 然后将 :c 更改为 99.

({:a 1
  :b "this one"
  :c 100}
 {:a "A"
  :c "Q"
  :z "Z"})

这是一种方法:

(ns tst.demo.core
  (:use tupelo.core tupelo.test))

(dotest
  (let [data   [{:a 1
                 :b "this one"
                 :c 100}
                {:a "A"
                 :c "Q"
                 :z "Z"}]
        result (vec (for [curr-map data]
                      (if (= "this one" (:b curr-map))
                        (assoc curr-map :c 99)
                        curr-map)))]
    (is= result
      [{:a 1, :b "this one", :c 99}
       {:a "A", :c "Q", :z "Z"}])))

基于 my favorite template project. Please see the list of documentation sources,尤其是。 Clojure CheatSheet 和 Getting Clojure

等书籍
(map #(if (= (:b %) "this one") (assoc % :c 99) %) data)