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

296 lines
8.4 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.modifyOption = exports.set = exports.composeTraversal = exports.composeOptional = exports.composeLens = exports.composeIso = exports.composePrism = exports.compose = exports.asTraversal = exports.asOptional = exports.fromPredicate = exports.id = exports.prism = void 0;
var function_1 = require("fp-ts/lib/function");
var O = require("fp-ts/lib/Option");
var pipeable_1 = require("fp-ts/lib/pipeable");
var _ = require("./internal");
// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
/**
* @category constructors
* @since 2.3.8
*/
exports.prism = _.prism;
/**
* @category constructors
* @since 2.3.0
*/
var id = function () { return (0, exports.prism)(O.some, function_1.identity); };
exports.id = id;
/**
* @category constructors
* @since 2.3.0
*/
exports.fromPredicate = _.prismFromPredicate;
// -------------------------------------------------------------------------------------
// converters
// -------------------------------------------------------------------------------------
/**
* View a `Prism` as a `Optional`.
*
* @category converters
* @since 2.3.0
*/
exports.asOptional = _.prismAsOptional;
/**
* View a `Prism` as a `Traversal`.
*
* @category converters
* @since 2.3.0
*/
exports.asTraversal = _.prismAsTraversal;
// -------------------------------------------------------------------------------------
// compositions
// -------------------------------------------------------------------------------------
/**
* Compose a `Prism` with a `Prism`.
*
* @category compositions
* @since 2.3.0
*/
exports.compose = _.prismComposePrism;
/**
* Alias of `compose`.
*
* @category compositions
* @since 2.3.8
*/
exports.composePrism = exports.compose;
/**
* Compose a `Prism` with a `Iso`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeIso =
/*#__PURE__*/
(0, function_1.flow)(_.isoAsPrism, exports.compose);
/**
* Compose a `Prism` with a `Lens`.
*
* @category compositions
* @since 2.3.0
*/
exports.composeLens = _.prismComposeLens;
/**
* Compose a `Prism` 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 `Prism` 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
*/
exports.set = _.prismSet;
/**
* @category combinators
* @since 2.3.0
*/
exports.modifyOption = _.prismModifyOption;
/**
* @category combinators
* @since 2.3.0
*/
exports.modify = _.prismModify;
function modifyF(F) {
return function (f) { return function (sa) { return function (s) {
return (0, pipeable_1.pipe)(sa.getOption(s), O.fold(function () { return F.of(s); }, function (a) { return F.map(f(a), sa.reverseGet); }));
}; }; };
}
exports.modifyF = modifyF;
/**
* Return a `Prism` from a `Prism` focused on a nullable value.
*
* @category combinators
* @since 2.3.3
*/
exports.fromNullable =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismFromNullable());
function filter(predicate) {
return (0, exports.compose)(_.prismFromPredicate(predicate));
}
exports.filter = filter;
/**
* Return a `Optional` from a `Prism` and a prop.
*
* @category combinators
* @since 2.3.0
*/
var prop = function (prop) {
return (0, exports.composeLens)((0, pipeable_1.pipe)(_.lensId(), _.lensProp(prop)));
}; // TODO: simplify?
exports.prop = prop;
/**
* Return a `Optional` from a `Prism` and a list of props.
*
* @category combinators
* @since 2.3.0
*/
var props = function () {
var props = [];
for (var _i = 0; _i < arguments.length; _i++) {
props[_i] = arguments[_i];
}
return (0, exports.composeLens)((0, pipeable_1.pipe)(_.lensId(), _.lensProps.apply(_, props)));
};
exports.props = props;
/**
* Return a `Optional` from a `Prism` focused on a component of a tuple.
*
* @category combinators
* @since 2.3.0
*/
var component = function (prop) { return (0, exports.composeLens)((0, pipeable_1.pipe)(_.lensId(), _.lensComponent(prop))); };
exports.component = component;
/**
* Return a `Optional` from a `Prism` 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 `Prism` 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 `Prism` 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 `Optional` from a `Prism` focused on a required key of a `ReadonlyRecord`.
*
* @category combinators
* @since 2.3.0
*/
var atKey = function (key) { return function (sa) {
return _.prismComposeLens(_.atReadonlyRecord().at(key))(sa);
}; };
exports.atKey = atKey;
/**
* Return a `Prism` from a `Prism` focused on the `Some` of a `Option` type.
*
* @category combinators
* @since 2.3.0
*/
exports.some =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismSome());
/**
* Return a `Prism` from a `Prism` focused on the `Right` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.right =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismRight());
/**
* Return a `Prism` from a `Prism` focused on the `Left` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.left =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismLeft());
/**
* Return a `Traversal` from a `Prism` 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.prism)((0, function_1.flow)(ea.getOption, O.map(ab)), (0, function_1.flow)(ba, ea.reverseGet)); };
/**
* @category instances
* @since 2.3.0
*/
exports.URI = 'monocle-ts/Prism';
/**
* @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
};