monads.state
Pass an updatable state through a computation.
asks
(asks f)
Apply f to the current state, and return the result.
State is unmodified.
chain-state
macro
(chain-state & args)
Chain multiple stateful computations together, discarding
the value along the way.
eval-state
(eval-state state-fn init-state)
Run a stateful computation with init-state.
Returns the final value sans the final state.
exec-state
(exec-state state-fn init-state)
Run a stateful computation with init-state.
Returns the final state.
inspect
(inspect state)
Place anywhere in a set of routes to have the current
state printed. Has no effect otherwise.
return-state
(return-state v)
Wrap a value in a state context.
run-state
(run-state state-fn init-state)
Run a stateful computation with init-state.
Returns the final value/state pair.
set-state
(set-state state)
Overwrite the current state.
state->
macro
(state-> bindings body)
Takes a vector of bindings and a final body. State will
be passed to each value on the righthand side of the
bindings vector, and to the final body value.
state-tuple
(state-tuple)
(state-tuple state)
(state-tuple val state)
Returns a state tuple give no value, a value, or a value
and some state. Serves as a more explicit indication of state
than a simple vector pair.
stateE->
macro
(stateE-> bindings body)
Like state-> except the value should be an Either.
Execution will stop when the first [:err ...] value is encountered.
statefn
macro
(statefn bindings & body)
Create a state function. Automatically propagates state.
Useful if you only want to read the state and not modify
it.
stateM->
macro
(stateM-> bindings body)
Like state-> except the value should be a Maybe.
Execution will stop when the first nil value is encountered.
update-state
(update-state f)
(update-state f & args)
Apply f and args to the current state.
wrap-state-either
(wrap-state-either state-fn)
Takes a state fn and creates a new state fn where the
value returned is wrapped in an [:ok ...].