Akh Javascript Monad Library
State Monad and Monad Transformer forThe StateT
monad transformer adds state to a monad. The base type State
provides state on its own.
# To use as standalone package $ npm install --save akh.state # To use as part of akh library $ npm install --save akh
Api
StateT
and State
implement the Fantasy Land]fl monad, monoid, functor, and applicative functor interfaces.
// State monadStateState // State monad transformerStateTStateT
State.run(m, s)
, m.run(s)
Perform a stateful computation m
with state s
and return state, value pair.
const State = State const c = State === 'value': 'val' 'state': 's1'
State.eval(m, s)
, m.eval(s)
Perform a stateful computation m
with state s
and return the resulting value.
State === 'val'
State.exec(m, s)
, m.exe(s)
Perform a stateful computation m
with state s
and return the resulting state.
State == 's'
StateT.run(m, s)
Same as State.run
but for transformed types.
StateT.evalT(m, s)
Same as State.eval
but for transformed types.
StateT.exec(m, s)
Same as State.exec
but for transformed types.
State Interface
All state operations and methods are defined on both the type and its instances.
M.get
Get the current state.
const State = State Stateget === value: 'my state' state: 'my state'
M.put(s)
Set the current state to s
M.modify(f)
Modify the current state with f
that maps the current state to a new state.
Contributing
Contributions are welcome.
To get started:
$ cd akh-state$ npm install # install dev packages $ npm test # run tests