Innovenergy_trunk/frontend/node_modules/fp-ts/lib/Separated.js

107 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
/**
* ```ts
* interface Separated<E, A> {
* readonly left: E
* readonly right: A
* }
* ```
*
* Represents a result of separating a whole into two parts.
*
* @since 2.10.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.right = exports.left = exports.flap = exports.Functor = exports.Bifunctor = exports.URI = exports.bimap = exports.mapLeft = exports.map = exports.separated = void 0;
var function_1 = require("./function");
var Functor_1 = require("./Functor");
// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
/**
* @category constructors
* @since 2.10.0
*/
var separated = function (left, right) { return ({ left: left, right: right }); };
exports.separated = separated;
var _map = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.map)(f)); };
var _mapLeft = function (fa, f) { return (0, function_1.pipe)(fa, (0, exports.mapLeft)(f)); };
var _bimap = function (fa, g, f) { return (0, function_1.pipe)(fa, (0, exports.bimap)(g, f)); };
/**
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
* use the type constructor `F` to represent some computational context.
*
* @category mapping
* @since 2.10.0
*/
var map = function (f) {
return function (fa) {
return (0, exports.separated)((0, exports.left)(fa), f((0, exports.right)(fa)));
};
};
exports.map = map;
/**
* Map a function over the first type argument of a bifunctor.
*
* @category error handling
* @since 2.10.0
*/
var mapLeft = function (f) {
return function (fa) {
return (0, exports.separated)(f((0, exports.left)(fa)), (0, exports.right)(fa));
};
};
exports.mapLeft = mapLeft;
/**
* Map a pair of functions over the two type arguments of the bifunctor.
*
* @category mapping
* @since 2.10.0
*/
var bimap = function (f, g) {
return function (fa) {
return (0, exports.separated)(f((0, exports.left)(fa)), g((0, exports.right)(fa)));
};
};
exports.bimap = bimap;
/**
* @category type lambdas
* @since 2.10.0
*/
exports.URI = 'Separated';
/**
* @category instances
* @since 2.10.0
*/
exports.Bifunctor = {
URI: exports.URI,
mapLeft: _mapLeft,
bimap: _bimap
};
/**
* @category instances
* @since 2.10.0
*/
exports.Functor = {
URI: exports.URI,
map: _map
};
/**
* @category mapping
* @since 2.10.0
*/
exports.flap = (0, Functor_1.flap)(exports.Functor);
// -------------------------------------------------------------------------------------
// utils
// -------------------------------------------------------------------------------------
/**
* @since 2.10.0
*/
var left = function (s) { return s.left; };
exports.left = left;
/**
* @since 2.10.0
*/
var right = function (s) { return s.right; };
exports.right = right;