48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.getFunctorComposition = exports.let = exports.bindTo = exports.flap = exports.map = void 0;
|
||
|
/**
|
||
|
* A `Functor` is a type constructor which supports a mapping operation `map`.
|
||
|
*
|
||
|
* `map` can be used to turn functions `a -> b` into functions `f a -> f b` whose argument and return types use the type
|
||
|
* constructor `f` to represent some computational context.
|
||
|
*
|
||
|
* Instances must satisfy the following laws:
|
||
|
*
|
||
|
* 1. Identity: `F.map(fa, a => a) <-> fa`
|
||
|
* 2. Composition: `F.map(fa, a => bc(ab(a))) <-> F.map(F.map(fa, ab), bc)`
|
||
|
*
|
||
|
* @since 2.0.0
|
||
|
*/
|
||
|
var function_1 = require("./function");
|
||
|
function map(F, G) {
|
||
|
return function (f) { return function (fa) { return F.map(fa, function (ga) { return G.map(ga, f); }); }; };
|
||
|
}
|
||
|
exports.map = map;
|
||
|
function flap(F) {
|
||
|
return function (a) { return function (fab) { return F.map(fab, function (f) { return f(a); }); }; };
|
||
|
}
|
||
|
exports.flap = flap;
|
||
|
function bindTo(F) {
|
||
|
return function (name) { return function (fa) { return F.map(fa, function (a) {
|
||
|
var _a;
|
||
|
return (_a = {}, _a[name] = a, _a);
|
||
|
}); }; };
|
||
|
}
|
||
|
exports.bindTo = bindTo;
|
||
|
function let_(F) {
|
||
|
return function (name, f) { return function (fa) { return F.map(fa, function (a) {
|
||
|
var _a;
|
||
|
return Object.assign({}, a, (_a = {}, _a[name] = f(a), _a));
|
||
|
}); }; };
|
||
|
}
|
||
|
exports.let = let_;
|
||
|
/** @deprecated */
|
||
|
function getFunctorComposition(F, G) {
|
||
|
var _map = map(F, G);
|
||
|
return {
|
||
|
map: function (fga, f) { return (0, function_1.pipe)(fga, _map(f)); }
|
||
|
};
|
||
|
}
|
||
|
exports.getFunctorComposition = getFunctorComposition;
|