Innovenergy_trunk/frontend/node_modules/fp-ts/es6/Applicative.js

40 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

/**
* The `Applicative` type class extends the `Apply` type class with a `of` function, which can be used to create values
* of type `f a` from values of type `a`.
*
* Where `Apply` provides the ability to lift functions of two or more arguments to functions whose arguments are
* wrapped using `f`, and `Functor` provides the ability to lift functions of one argument, `pure` can be seen as the
* function which lifts functions of _zero_ arguments. That is, `Applicative` functors support a lifting operation for
* any number of function arguments.
*
* Instances must satisfy the following laws in addition to the `Apply` laws:
*
* 1. Identity: `A.ap(A.of(a => a), fa) <-> fa`
* 2. Homomorphism: `A.ap(A.of(ab), A.of(a)) <-> A.of(ab(a))`
* 3. Interchange: `A.ap(fab, A.of(a)) <-> A.ap(A.of(ab => ab(a)), fab)`
*
* Note. `Functor`'s `map` can be derived: `A.map(x, f) = A.ap(A.of(f), x)`
*
* @since 2.0.0
*/
import { ap, getApplySemigroup } from './Apply';
import { pipe } from './function';
import { getFunctorComposition } from './Functor';
export function getApplicativeMonoid(F) {
var f = getApplySemigroup(F);
return function (M) { return ({
concat: f(M).concat,
empty: F.of(M.empty)
}); };
}
/** @deprecated */
export function getApplicativeComposition(F, G) {
var map = getFunctorComposition(F, G).map;
var _ap = ap(F, G);
return {
map: map,
of: function (a) { return F.of(G.of(a)); },
ap: function (fgab, fga) { return pipe(fgab, _ap(fga)); }
};
}