Return a state-monad function that assumes the state to be a map and
replaces the value associated with the given key by the return value
of f applied to the old value. The old value is returned.
(defn update-val
"Return a state-monad function that assumes the state to be a map and
replaces the value associated with the given key by the return value
of f applied to the old value. The old value is returned."
[key f]
(fn [s]
(let [old-val (get s key)
new-s (assoc s key (f old-val))]
[old-val new-s])))
Comments top
No comments for update-val. Log in to add a comment.