1.2.0 permalink Arrow_down_16x16

with-state-field

clojure.contrib.monads

  • (with-state-field key statement)
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.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/monads.clj:389 top

(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])))
Vars in clojure.contrib.monads/with-state-field: defn fn let
Used in 0 other vars

Comments top

No comments for with-state-field. Log in to add a comment.