@fpjs/overture
Version:
A Javascript prelude
30 lines (29 loc) • 990 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "ap", {
enumerable: true,
get: function () {
return _apply.ap;
}
});
exports.pure = exports.of = exports.lift2 = exports.lift = exports.isApplicative = void 0;
var _base = require("@fpjs/overture/base");
var _apply = require("@fpjs/overture/algebras/apply");
var _functor = require("@fpjs/overture/algebras/functor");
const isApplicative = x => (0, _apply.isApply)(x) && "fantasy-land/of" in (0, _base.typerep)(x);
exports.isApplicative = isApplicative;
const pure = F => x => {
const op = F["fantasy-land/of"];
if (op === undefined) {
throw TypeError(`'${F.name}' is not an Applicative.`);
}
return op(x);
};
exports.pure = pure;
const of = exports.of = pure;
const lift = ab => a => (0, _apply.ap)(pure((0, _base.typerep)(a))(ab))(a);
exports.lift = lift;
const lift2 = abc => a => b => (0, _apply.ap)((0, _functor.map)(abc)(a))(b);
exports.lift2 = lift2;