UNPKG

monocle-ts-esm

Version:

A porting of scala monocle library to TypeScript

109 lines (108 loc) 3.81 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.indexRecord = exports.indexArray = exports.indexReadonlyMap = exports.indexReadonlyRecord = exports.indexReadonlyNonEmptyArray = exports.indexReadonlyArray = exports.fromIso = exports.fromAt = exports.index = void 0; /** * **This module is experimental** * * Experimental features are published in order to get early feedback from the community. * * A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice. * * @since 2.3.0 */ const O = __importStar(require("fp-ts-esm/Option")); const pipeable_1 = require("fp-ts-esm/pipeable"); const _ = __importStar(require("./internal.js")); const RM = __importStar(require("fp-ts-esm/ReadonlyMap")); // ------------------------------------------------------------------------------------- // constructors // ------------------------------------------------------------------------------------- /** * @category constructors * @since 2.3.8 */ exports.index = _.index; /** * @category constructors * @since 2.3.0 */ const fromAt = (at) => (0, exports.index)((i) => _.lensComposePrism(_.prismSome())(at.at(i))); exports.fromAt = fromAt; /** * Lift an instance of `Index` using an `Iso`. * * @category constructors * @since 2.3.0 */ const fromIso = (iso) => (sia) => (0, exports.index)((i) => (0, pipeable_1.pipe)(iso, _.isoAsOptional, _.optionalComposeOptional(sia.index(i)))); exports.fromIso = fromIso; /** * @category constructors * @since 2.3.7 */ exports.indexReadonlyArray = _.indexReadonlyArray; /** * @category constructors * @since 2.3.8 */ exports.indexReadonlyNonEmptyArray = _.indexReadonlyNonEmptyArray; /** * @category constructors * @since 2.3.7 */ exports.indexReadonlyRecord = _.indexReadonlyRecord; /** * @category constructors * @since 2.3.7 */ const indexReadonlyMap = (E) => { const lookupE = RM.lookup(E); const insertAtE = RM.insertAt(E); return () => (0, exports.index)((key) => _.optional((s) => lookupE(key, s), (next) => { const insert = insertAtE(key, next); return (s) => (0, pipeable_1.pipe)(lookupE(key, s), O.fold(() => s, (prev) => (next === prev ? s : insert(s)))); })); }; exports.indexReadonlyMap = indexReadonlyMap; // ------------------------------------------------------------------------------------- // deprecated // ------------------------------------------------------------------------------------- /** * Use `indexReadonlyArray` instead. * * @category constructors * @since 2.3.2 * @deprecated */ exports.indexArray = _.indexReadonlyArray; /** * Use `indexReadonlyRecord` instead. * * @category constructors * @since 2.3.2 * @deprecated */ exports.indexRecord = _.indexReadonlyRecord;