Monad.State
The State monad.
The State monad allows for stateful computations while using pure functions. Computations of this kind can be represented by state transformers, i.e. by functions that map an initial state to a result value paired with a final state.
Examples
iex> require Monad.State, as: State
iex> import State
iex> s = State.m do
...> a <- get
...> put (a + 1)
...> return a + 10
...> end
iex> State.run(2, s)
{12, 3}
Summary
Functions
Callback implementation for Monad.bind/2
Get the state
Modify the state
Set a new state
Inject x
into a State monad
Run the State monad m
with x
as the value of the initial state
Types
Functions
Callback implementation for Monad.bind/2
.
Macros
Monad do-notation.
See the Monad
module documentation and the
Monad.State
module documentation