UNPKG

3.02 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.indexRecord = exports.indexArray = exports.indexReadonlyMap = exports.indexReadonlyRecord = exports.indexReadonlyNonEmptyArray = exports.indexReadonlyArray = exports.fromIso = exports.fromAt = exports.index = void 0;
4/**
5 * **This module is experimental**
6 *
7 * Experimental features are published in order to get early feedback from the community.
8 *
9 * A feature tagged as _Experimental_ is in a high state of flux, you're at risk of it changing without notice.
10 *
11 * @since 2.3.0
12 */
13var O = require("fp-ts/lib/Option");
14var pipeable_1 = require("fp-ts/lib/pipeable");
15var _ = require("./internal");
16var RM = require("fp-ts/lib/ReadonlyMap");
17// -------------------------------------------------------------------------------------
18// constructors
19// -------------------------------------------------------------------------------------
20/**
21 * @category constructors
22 * @since 2.3.8
23 */
24exports.index = _.index;
25/**
26 * @category constructors
27 * @since 2.3.0
28 */
29var fromAt = function (at) {
30 return (0, exports.index)(function (i) { return _.lensComposePrism(_.prismSome())(at.at(i)); });
31};
32exports.fromAt = fromAt;
33/**
34 * Lift an instance of `Index` using an `Iso`.
35 *
36 * @category constructors
37 * @since 2.3.0
38 */
39var fromIso = function (iso) { return function (sia) {
40 return (0, exports.index)(function (i) { return (0, pipeable_1.pipe)(iso, _.isoAsOptional, _.optionalComposeOptional(sia.index(i))); });
41}; };
42exports.fromIso = fromIso;
43/**
44 * @category constructors
45 * @since 2.3.7
46 */
47exports.indexReadonlyArray = _.indexReadonlyArray;
48/**
49 * @category constructors
50 * @since 2.3.8
51 */
52exports.indexReadonlyNonEmptyArray = _.indexReadonlyNonEmptyArray;
53/**
54 * @category constructors
55 * @since 2.3.7
56 */
57exports.indexReadonlyRecord = _.indexReadonlyRecord;
58/**
59 * @category constructors
60 * @since 2.3.7
61 */
62var indexReadonlyMap = function (E) {
63 var lookupE = RM.lookup(E);
64 var insertAtE = RM.insertAt(E);
65 return function () {
66 return (0, exports.index)(function (key) {
67 return _.optional(function (s) { return lookupE(key, s); }, function (next) {
68 var insert = insertAtE(key, next);
69 return function (s) {
70 return (0, pipeable_1.pipe)(lookupE(key, s), O.fold(function () { return s; }, function (prev) { return (next === prev ? s : insert(s)); }));
71 };
72 });
73 });
74 };
75};
76exports.indexReadonlyMap = indexReadonlyMap;
77// -------------------------------------------------------------------------------------
78// deprecated
79// -------------------------------------------------------------------------------------
80/**
81 * Use `indexReadonlyArray` instead.
82 *
83 * @category constructors
84 * @since 2.3.2
85 * @deprecated
86 */
87exports.indexArray = _.indexReadonlyArray;
88/**
89 * Use `indexReadonlyRecord` instead.
90 *
91 * @category constructors
92 * @since 2.3.2
93 * @deprecated
94 */
95exports.indexRecord = _.indexReadonlyRecord;