$ npm install --save akh
Akh can either be used as a single library, or you can pick up individual types from split out libraries. See each library for more documentation on that type.
All functions from akh.core are top level exports.
const List = Listconst StateT = StateT// Define a new monad using the state transformer on the list monad.const M =// Define a way to pass values through `M`const run = List// Create a simple stateful computation with an initial valueconst start = M// Run the stateful computation to get a list of// value, state pairs===value: 'porky' state: 'wackyland'// Let's update the current state using a functionconst modifiedState = start===value: 'WACKYLAND' state: 'WACKYLAND'// Note that modify also updated the held value here. We could avoid that// by instead writingconst modifiedState2 = start===value: 'porky' state: 'WACKYLAND'// Now let's start using the list monad and branch the state.const branched = modifiedState2===value: 'porky' state: 'WACKYLAND'value: 100 state: 'nuts'value: 1 state: 'squirrel'value: 'wackyland' state: 'wackyland'// We can then operate on all states at the same time.const doubled = branched===value: 'porkyporky' state: 'WACKYLAND'value: 200 state: 'nuts'value: 2 state: 'squirrel'value: 'wackylandwackyland' state: 'wackyland'
Improvement and additions to Akh are welcome. Please report any issues or send a pull request.
The Dodo Bird is a Looney Toons character created and owned by Warner Bros.