Returns a state-monad function that expects a map as its state and
runs statement (another state-monad function) on the state defined by
the map entry corresponding to key. The map entry is updated with the
new state returned by statement.
(defn with-state-field
"Returns a state-monad function that expects a map as its state and
runs statement (another state-monad function) on the state defined by
the map entry corresponding to key. The map entry is updated with the
new state returned by statement."
[key statement]
(fn [s]
(let [substate (get s key nil)
[result new-substate] (statement substate)
new-state (assoc s key new-substate)]
[result new-state])))
Comments top
No comments for with-state-field. Log in to add a comment.