Akh - noun
1) Large flightless bird found in Fantasy Land
2) Javascript monad transformer library
$ npm install --save akh
Overview
Akh is a collection of monad and monad transformers that implement Fantasy Land's interfaces. It is inspired by Haskell's MTL.
Usage
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.
Monad Transformers
- akh.ContT - Continuation transformer. (Monad, Functor, Applicative Functor)
- akh.DContT - Delimited continuation transformer. (Monad, Functor, Applicative Functor)
- akh.EitherT - Either transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.ErrorT - Error transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.IdentityT - Transforms a monad to itself. (Monad, Functor, Applicative Functor)
- akh.ListT - List transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.MaybeT - Maybe transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.ReaderT - Reader transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.StateT - State transformer. (Monad, Monoid, Functor, Applicative Functor)
- akh.UniqueT - Get unique int value (Monad, Monoid, Functor, Applicative Functor)
- akh.WriterT - Writer transformer. (Monad, Monoid, Functor, Applicative Functor)
Monads
- akh.Cont - Continuation computation. (Monad, Functor, Applicative Functor)
- akh.DCont - Delimited continuation computation. (Monad, Functor, Applicative Functor)
- akh.Either - Either computation. (Monad, Functor, Applicative Functor)
- akh.Error - Error computation. (Monad, Functor, Applicative Functor)
- akh.Identity - Identity computation. (Monad, Functor, Applicative Functor)
- akh.List - List computation. (Monad, Monoid, Functor, Applicative Functor)
- akh.Maybe - Computation that may produce a value or nothing. (Monad, Monoid, Functor, Applicative Functor)
- akh.Reader - Reader monad. (Monad, Monoid, Functor, Applicative Functor)
- akh.State – Stateful computation. (Monad, Functor, Applicative Functor)
- akh.Unique – Get Unique int (Monad, Monoid, Functor, Applicative Functor)
- akh.Writer - Writer monad. (Monad, Monoid, Functor, Applicative Functor)
Quick Example
const List = require('akh').List
const StateT = require('akh').StateT
const M = StateT(List)
const run = (c, state) => List.runList(StateT.runStateT(c, state))
const start = M.of('porky')
run(start, 'wackyland') === [
{ value: 'porky', state: 'wackyland' }
]
const modifiedState = start.modify(state => state.toUpperCase())
run(modifiedState, 'wackyland') === [
{ value: 'WACKYLAND', state: 'WACKYLAND' }
]
const modifiedState2 = start
.chain(currentValue =>
M.modify(state => state.toUpperCase())
.map(_ => currentValue))
run(modifiedState2, 'wackyland') === [
{ value: 'porky', state: 'WACKYLAND' }
]
const branched = modifiedState2
.concat(
M.put('nuts').map(_ => 100)
)
.concat(
M.put('squirrel').map(_ => 1)
)
.concat(
M.get
)
run(branched, 'wackyland') === [
{ value: 'porky', state: 'WACKYLAND' },
{ value: 100, state: 'nuts' },
{ value: 1, state: 'squirrel' },
{ value: 'wackyland', state: 'wackyland' }
]
const doubled = branched.map(x => x + x)
run(doubled, 'wackyland') === [
{ value: 'porkyporky', state: 'WACKYLAND' },
{ value: 200, state: 'nuts' },
{ value: 2, state: 'squirrel' },
{ value: 'wackylandwackyland', state: 'wackyland' }
]
Contribute
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.