Innovenergy_trunk/frontend/node_modules/monocle-ts/lib/Lens.js

269 lines
7.5 KiB
JavaScript
Raw Normal View History

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Category = exports.Semigroupoid = exports.Invariant = exports.URI = exports.imap = exports.findFirstNonEmpty = exports.findFirst = exports.traverse = exports.left = exports.right = exports.some = exports.atKey = exports.key = exports.indexNonEmpty = exports.index = exports.component = exports.props = exports.prop = exports.filter = exports.fromNullable = exports.modifyF = exports.modify = exports.composeTraversal = exports.composeOptional = exports.composePrism = exports.composeIso = exports.composeLens = exports.compose = exports.asTraversal = exports.asOptional = exports.id = exports.lens = void 0;
var function_1 = require("fp-ts/lib/function");
var pipeable_1 = require("fp-ts/lib/pipeable");
var _ = require("./internal");
// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
/**
* @category constructors
* @since 2.3.8
*/
exports.lens = _.lens;
/**
* @category constructors
* @since 2.3.0
*/
exports.id = _.lensId;
// -------------------------------------------------------------------------------------
// converters
// -------------------------------------------------------------------------------------
/**
* View a `Lens` as a `Optional`.
*
* @category converters
* @since 2.3.0
*/
exports.asOptional = _.lensAsOptional;
/**
* View a `Lens` as a `Traversal`.
*
* @category converters
* @since 2.3.0
*/
exports.asTraversal = _.lensAsTraversal;
// -------------------------------------------------------------------------------------
// compositions
// -------------------------------------------------------------------------------------
/**
* Compose a `Lens` with a `Lens`.
*
* @category compositions
* @since 2.3.0
*/
exports.compose = _.lensComposeLens;
/**
* Alias of `compose`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeLens = exports.compose;
/**
* Compose a `Lens` with a `Iso`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeIso =
/*#__PURE__*/
(0, function_1.flow)(_.isoAsLens, exports.compose);
/**
* Compose a `Lens` with a `Prism`.
*
* @category compositions
* @since 2.3.0
*/
exports.composePrism = _.lensComposePrism;
/**
* Compose a `Lens` with an `Optional`.
*
* @category compositions
* @since 2.3.0
*/
var composeOptional = function (ab) {
return (0, function_1.flow)(exports.asOptional, _.optionalComposeOptional(ab));
};
exports.composeOptional = composeOptional;
/**
* Compose a `Lens` with an `Traversal`.
*
* @category compositions
* @since 2.3.8
*/
var composeTraversal = function (ab) {
return (0, function_1.flow)(exports.asTraversal, _.traversalComposeTraversal(ab));
};
exports.composeTraversal = composeTraversal;
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* @category combinators
* @since 2.3.0
*/
var modify = function (f) { return function (sa) { return function (s) {
var o = sa.get(s);
var n = f(o);
return o === n ? s : sa.set(n)(s);
}; }; };
exports.modify = modify;
function modifyF(F) {
return function (f) { return function (sa) { return function (s) { return (0, pipeable_1.pipe)(sa.get(s), f, function (fa) { return F.map(fa, function (a) { return sa.set(a)(s); }); }); }; }; };
}
exports.modifyF = modifyF;
/**
* Return a `Optional` from a `Lens` focused on a nullable value.
*
* @category combinators
* @since 2.3.0
*/
var fromNullable = function (sa) {
return (0, exports.composePrism)(_.prismFromNullable())(sa);
};
exports.fromNullable = fromNullable;
function filter(predicate) {
return (0, exports.composePrism)(_.prismFromPredicate(predicate));
}
exports.filter = filter;
/**
* Return a `Lens` from a `Lens` and a prop.
*
* @category combinators
* @since 2.3.0
*/
exports.prop = _.lensProp;
/**
* Return a `Lens` from a `Lens` and a list of props.
*
* @category combinators
* @since 2.3.0
*/
exports.props = _.lensProps;
/**
* Return a `Lens` from a `Lens` focused on a component of a tuple.
*
* @category combinators
* @since 2.3.0
*/
exports.component = _.lensComponent;
/**
* Return a `Optional` from a `Lens` focused on an index of a `ReadonlyArray`.
*
* @category combinators
* @since 2.3.0
*/
var index = function (i) {
return (0, function_1.flow)(exports.asOptional, _.optionalIndex(i));
};
exports.index = index;
/**
* Return a `Optional` from a `Lens` focused on an index of a `ReadonlyNonEmptyArray`.
*
* @category combinators
* @since 2.3.8
*/
var indexNonEmpty = function (i) {
return (0, function_1.flow)(exports.asOptional, _.optionalIndexNonEmpty(i));
};
exports.indexNonEmpty = indexNonEmpty;
/**
* Return a `Optional` from a `Lens` focused on a key of a `ReadonlyRecord`.
*
* @category combinators
* @since 2.3.0
*/
var key = function (key) {
return (0, function_1.flow)(exports.asOptional, _.optionalKey(key));
};
exports.key = key;
/**
* Return a `Lens` from a `Lens` focused on a required key of a `ReadonlyRecord`.
*
* @category combinators
* @since 2.3.0
*/
exports.atKey = _.lensAtKey;
/**
* Return a `Optional` from a `Lens` focused on the `Some` of a `Option` type.
*
* @category combinators
* @since 2.3.0
*/
exports.some =
/*#__PURE__*/
(0, exports.composePrism)(/*#__PURE__*/ _.prismSome());
/**
* Return a `Optional` from a `Lens` focused on the `Right` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.right =
/*#__PURE__*/
(0, exports.composePrism)(/*#__PURE__*/ _.prismRight());
/**
* Return a `Optional` from a `Lens` focused on the `Left` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.left =
/*#__PURE__*/
(0, exports.composePrism)(/*#__PURE__*/ _.prismLeft());
/**
* Return a `Traversal` from a `Lens` focused on a `Traversable`.
*
* @category combinators
* @since 2.3.0
*/
function traverse(T) {
return (0, function_1.flow)(exports.asTraversal, _.traversalTraverse(T));
}
exports.traverse = traverse;
function findFirst(predicate) {
return (0, exports.composeOptional)(_.optionalFindFirst(predicate));
}
exports.findFirst = findFirst;
function findFirstNonEmpty(predicate) {
return (0, exports.composeOptional)(_.optionalFindFirstNonEmpty(predicate));
}
exports.findFirstNonEmpty = findFirstNonEmpty;
// -------------------------------------------------------------------------------------
// pipeables
// -------------------------------------------------------------------------------------
/**
* @category Invariant
* @since 2.3.0
*/
var imap = function (f, g) { return function (ea) {
return imap_(ea, f, g);
}; };
exports.imap = imap;
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
var imap_ = function (ea, ab, ba) { return (0, exports.lens)((0, function_1.flow)(ea.get, ab), (0, function_1.flow)(ba, ea.set)); };
/**
* @category instances
* @since 2.3.0
*/
exports.URI = 'monocle-ts/Lens';
/**
* @category instances
* @since 2.3.0
*/
exports.Invariant = {
URI: exports.URI,
imap: imap_
};
/**
* @category instances
* @since 2.3.8
*/
exports.Semigroupoid = {
URI: exports.URI,
compose: function (ab, ea) { return (0, exports.compose)(ab)(ea); }
};
/**
* @category instances
* @since 2.3.0
*/
exports.Category = {
URI: exports.URI,
compose: exports.Semigroupoid.compose,
id: exports.id
};