The wrapped computation.
Run a computation, discarding the final state.
Run a computation, discarding the result.
Change the type of the result in an action.
const double = (n: number) => n * 2
const state = State.of(1).map(double)
state.eval(0) // 2
Get the current state.
const state = get()
state.eval(1) // 1
state.exec(1) // 1
Get a value which depends on the current state.
const state = gets(double)
state.eval(1) // 2
state.exec(1) // 1
Modify the state by applying a function to the current state.
const double = (n: number) => n * 2
const state = modify(double)
state.eval(1) // undefined
state.exec(1) // 2
Create a new state that will replace the return value when run.
Set the state.
const state = put(2)
state.eval(1) // undefined
state.exec(1) // 2
Generated using TypeDoc
State is a Monad with the operations
get
andput
, which can be used to model a single piece of mutable state (S) with a return value (A).