(defn do-to-map [amap keyseq f]
(reduce # (assoc% 1% 2 (f (% 1% 2))) amap keyseq))
Structure:
. Clojure - ; , , . , , :
(some-map some-key)
, f. , , :
(f (some-map some-key))
-, "" . , assoc :
(assoc some-map some-key (f (some-map some-key)))
( "" , -, , , - , assoc. Clojure, - , assoc .)
assoc , . - . - , "" . - "" . , , , -, "". , reduce.
reduce - , : "", , "" ; , , .reduce - , fn.reduce - , fn .
:
(reduce fn-to-update-values-in-our-map
initial-value-of-our-map
collection-of-keys)
fn-to-update-values-in-our-map - assoc , :
(fn [map-so-far some-key] (assoc map-so-far some-key (f (map-so-far some-key))))
, reduce:
(reduce (fn [map-so-far some-key] (assoc map-so-far some-key (f (map-so-far some-key))))
amap
keyseq)
Clojure : #(...) - fn, , %1 , %2 .. fn :
:
(reduce