Akh state monad and monad transformer
npm install akh.stateThe StateT monad transformer adds state to a monad. The base type State provides state on its own.
``bashTo use as standalone package
$ npm install --save akh.state
Api
StateT and State implement the Fantasy Land][fl] monad, monoid, functor, and applicative functor interfaces.`js
// State monad
require('akh.state').State
require('akh').State// State monad transformer
require('akh.state').StateT
require('akh').StateT
`####
State.run(m, s), m.run(s)
Perform a stateful computation m with state s and return state, value pair.`js
const State = require('akh.state').Stateconst c = State.of(1)
.chain(x => State.modify(s => s + x))
.chain(x => State.of('val'))
run(c, 's') === {'value': 'val', 'state': 's1'}
`####
State.eval(m, s), m.eval(s)
Perform a stateful computation m with state s and return the resulting value.`js
State.eval(c, 's') === 'val'
`####
State.exec(m, s), m.exe(s)
Perform a stateful computation m with state s and return the resulting state.`js
State.eval(c, 's') == '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.
`js
const State = require('akh.state').StateState.get.run('my state') === { 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:
`bash
$ cd akh-state
$ npm install # install dev packages
$ npm test # run tests
``[fl]: https://github.com/fantasyland/fantasy-land