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

281 lines
8.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Category = exports.Semigroupoid = exports.URI = exports.getAll = exports.fold = exports.foldMap = 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.set = exports.modify = exports.composeOptional = exports.composePrism = exports.composeLens = exports.composeIso = exports.composeTraversal = exports.compose = exports.fromTraversable = exports.id = exports.traversal = void 0;
var C = require("fp-ts/lib/Const");
var function_1 = require("fp-ts/lib/function");
var pipeable_1 = require("fp-ts/lib/pipeable");
var RA = require("fp-ts/lib/ReadonlyArray");
var _ = require("./internal");
// -------------------------------------------------------------------------------------
// constructors
// -------------------------------------------------------------------------------------
/**
* @category constructors
* @since 2.3.8
*/
exports.traversal = _.traversal;
/**
* @category constructors
* @since 2.3.0
*/
var id = function () { return (0, exports.traversal)(function (_) { return function (f) { return f; }; }); };
exports.id = id;
/**
* Create a `Traversal` from a `Traversable`.
*
* @category constructor
* @since 2.3.0
*/
exports.fromTraversable = _.fromTraversable;
// -------------------------------------------------------------------------------------
// compositions
// -------------------------------------------------------------------------------------
/**
* Compose a `Traversal` with a `Traversal`.
*
* @category compositions
* @since 2.3.0
*/
exports.compose = _.traversalComposeTraversal;
/**
* Alias of `compose`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeTraversal = exports.compose;
/**
* Compose a `Traversal` with a `Iso`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeIso =
/*#__PURE__*/
(0, function_1.flow)(_.isoAsTraversal, exports.compose);
/**
* Compose a `Traversal` with a `Lens`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeLens =
/*#__PURE__*/
(0, function_1.flow)(_.lensAsTraversal, _.traversalComposeTraversal);
/**
* Compose a `Traversal` with a `Prism`.
*
* @category compositions
* @since 2.3.8
*/
exports.composePrism =
/*#__PURE__*/
(0, function_1.flow)(_.prismAsTraversal, _.traversalComposeTraversal);
/**
* Compose a `Traversal` with a `Optional`.
*
* @category compositions
* @since 2.3.8
*/
exports.composeOptional =
/*#__PURE__*/
(0, function_1.flow)(_.optionalAsTraversal, _.traversalComposeTraversal);
// -------------------------------------------------------------------------------------
// combinators
// -------------------------------------------------------------------------------------
/**
* @category combinators
* @since 2.3.0
*/
var modify = function (f) { return function (sa) {
return sa.modifyF(_.ApplicativeIdentity)(f);
}; };
exports.modify = modify;
/**
* @category combinators
* @since 2.3.0
*/
var set = function (a) { return (0, exports.modify)(function () { return a; }); };
exports.set = set;
/**
* Return a `Traversal` from a `Traversal` 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.compose)(_.prismAsTraversal(_.prismFromPredicate(predicate)));
}
exports.filter = filter;
/**
* Return a `Traversal` from a `Traversal` and a prop.
*
* @category combinators
* @since 2.3.0
*/
var prop = function (prop) {
return (0, exports.compose)((0, pipeable_1.pipe)(_.lensId(), _.lensProp(prop), _.lensAsTraversal));
};
exports.prop = prop;
/**
* Return a `Traversal` from a `Traversal` 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.compose)((0, pipeable_1.pipe)(_.lensId(), _.lensProps.apply(_, props), _.lensAsTraversal));
};
exports.props = props;
/**
* Return a `Traversal` from a `Traversal` focused on a component of a tuple.
*
* @category combinators
* @since 2.3.0
*/
var component = function (prop) {
return (0, exports.compose)((0, pipeable_1.pipe)(_.lensId(), _.lensComponent(prop), _.lensAsTraversal));
};
exports.component = component;
/**
* Return a `Traversal` from a `Traversal` focused on an index of a `ReadonlyArray`.
*
* @category combinators
* @since 2.3.0
*/
var index = function (i) { return function (sa) {
return (0, pipeable_1.pipe)(sa, (0, exports.compose)(_.optionalAsTraversal(_.indexReadonlyArray().index(i))));
}; };
exports.index = index;
/**
* @category combinators
* @since 2.3.8
*/
var indexNonEmpty = function (i) { return function (sa) {
return (0, pipeable_1.pipe)(sa, (0, exports.compose)(_.optionalAsTraversal(_.indexReadonlyNonEmptyArray().index(i))));
}; };
exports.indexNonEmpty = indexNonEmpty;
/**
* Return a `Traversal` from a `Traversal` focused on a key of a `ReadonlyRecord`.
*
* @category combinators
* @since 2.3.0
*/
var key = function (key) { return function (sa) {
return (0, pipeable_1.pipe)(sa, (0, exports.compose)(_.optionalAsTraversal(_.indexReadonlyRecord().index(key))));
}; };
exports.key = key;
/**
* Return a `Traversal` from a `Traversal` focused on a required key of a `ReadonlyRecord`.
*
* @category combinators
* @since 2.3.0
*/
var atKey = function (key) { return function (sa) {
return (0, pipeable_1.pipe)(sa, (0, exports.compose)(_.lensAsTraversal(_.atReadonlyRecord().at(key))));
}; };
exports.atKey = atKey;
/**
* Return a `Traversal` from a `Traversal` focused on the `Some` of a `Option` type.
*
* @category combinators
* @since 2.3.0
*/
exports.some =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismAsTraversal(/*#__PURE__*/ _.prismSome()));
/**
* Return a `Traversal` from a `Traversal` focused on the `Right` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.right =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismAsTraversal(/*#__PURE__*/ _.prismRight()));
/**
* Return a `Traversal` from a `Traversal` focused on the `Left` of a `Either` type.
*
* @category combinators
* @since 2.3.0
*/
exports.left =
/*#__PURE__*/
(0, exports.compose)(/*#__PURE__*/ _.prismAsTraversal(/*#__PURE__*/ _.prismLeft()));
/**
* Return a `Traversal` from a `Traversal` focused on a `Traversable`.
*
* @category combinators
* @since 2.3.0
*/
exports.traverse = _.traversalTraverse;
function findFirst(predicate) {
return (0, exports.composeOptional)(_.optionalFindFirst(predicate));
}
exports.findFirst = findFirst;
function findFirstNonEmpty(predicate) {
return (0, exports.composeOptional)(_.optionalFindFirstNonEmpty(predicate));
}
exports.findFirstNonEmpty = findFirstNonEmpty;
/**
* Map each target to a `Monoid` and combine the results.
*
* @category combinators
* @since 2.3.0
*/
var foldMap = function (M) { return function (f) { return function (sa) {
return sa.modifyF(C.getApplicative(M))(function (a) { return C.make(f(a)); });
}; }; };
exports.foldMap = foldMap;
/**
* Map each target to a `Monoid` and combine the results.
*
* @category combinators
* @since 2.3.0
*/
var fold = function (M) { return (0, exports.foldMap)(M)(function_1.identity); };
exports.fold = fold;
/**
* Get all the targets of a `Traversal`.
*
* @category combinators
* @since 2.3.0
*/
var getAll = function (s) { return function (sa) {
return (0, exports.foldMap)(RA.getMonoid())(RA.of)(sa)(s);
}; };
exports.getAll = getAll;
// -------------------------------------------------------------------------------------
// instances
// -------------------------------------------------------------------------------------
/**
* @category instances
* @since 2.3.0
*/
exports.URI = 'monocle-ts/Traversal';
/**
* @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
};