Module: control.monads

Stability:1 - Experimental
Bug Tracker:https://github.com/folktale/control.monads/issues
Version:0.6.0
Repository:https://github.com/folktale/control.monads
Portability:Portable
npm package:control.monads

Common monadic combinators and sequencing operations.

Loading

Require the control.monads package, after installing it:

var monads = require('control.monads')

Uncategorised

sequence()

control.monads.sequence(type, monads)
Returns:A monad containing an array of the values.
m:Monad(_) => m → Array(m(α)) → m(Array(α))

mapM()

control.monads.mapM(type, transformation, values)
Returns:A monad containing an array of the values.
m:Monad(_) => m → (α → m(β)) → Array(α) → m(Array(β))

Converts each value into a monadic action, then evaluates such actions, left to right, and collects their results.

compose()

control.monads.compose(f, g, value)
Returns:A composition of the given functions on monads.
m:Monad(_) => (α → m(β)) → (β → m(γ)) → α → m(γ)

Left-to-right Kleisi composition of monads.

rightCompose()

control.monads.rightCompose(f, g, value)
Returns:A composition of the given functions on monads.
m:Monad(_) => (β → m(γ)) → (α → m(β)) → α → m(γ)

Right-to-left Kleisi composition of monads.

join()

control.monads.join(monad)
Returns:The nested monad.
m:Monad(_) => m(m(α)) → m(α)

Removes one level of nesting for a nested monad.

filterM()

control.monads.filterM(type, predicate, values)
Returns:An array with values that pass the predicate, inside a monad.
m:Monad(_) => m → (α → m(Boolean)) → Array(α) → m(Array(α))

Filters the contents of an array with a predicate returning a monad.

liftM2()

control.monads.liftM2(transformation, monad1, monad2)
Returns:The transformed value inside a monad.
m:Monad(_) => (α, β → γ) → m(α) → m(β) → m(γ)

Promotes a regular binary function to a function over monads.

liftMN()

control.monads.liftMN(transformation, values)
Returns:The transformed value inside a monad.
m:Monad(_) => (α₁, α₂, ..., αₙ → β)
            → Array(m(α₁), m(α₂), ..., m(αₙ))
            → m(β) :: throws

Promotes a regular function of arity N to a function over monads.

Curried methods

concat()

control.monads.concat(left, right)
Returns:A new semigroup with the values combined.
s:Semigroup(_) => s(α) → s(α) → s(α)

Concatenates two semigroups.

empty()

control.monads.empty()
Returns:A new empty semigroup.
s:Semigroup(_) => s → s(α)

map()

control.monads.map(transformation, functor)
Returns:A functor with its contents transformed by f.
f:Functor(_) => (α → β) → f(α) → f(β)

Maps over a functor instance.

of()

control.monads.of(value, type)
Returns:A new applicative instance containing the given value.
f:Applicative(_) => α → f → f(α)

Constructs a new applicative intance.

ap()

control.monads.ap(transformation, applicative)
Returns:A new applicative with values transformed by the receiver.
f:Applicative(_) => f(α → β) → f(α) → f(β)

Applies the function of an Applicative to the values of another Applicative.

chain()

control.monads.chain(transformation, monad)
Returns:A new monad as transformed by the function.
c:Chain(_) => (α → c(β)) → c(α) → c(β)

Transforms the values of a monad into a new monad.