UNPKG

2.37 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.atRecord = exports.atReadonlySet = exports.atReadonlyMap = exports.atReadonlyRecord = exports.fromIso = exports.at = void 0;
4var O = require("fp-ts/lib/Option");
5var pipeable_1 = require("fp-ts/lib/pipeable");
6var RM = require("fp-ts/lib/ReadonlyMap");
7var RS = require("fp-ts/lib/ReadonlySet");
8var _ = require("./internal");
9// -------------------------------------------------------------------------------------
10// constructors
11// -------------------------------------------------------------------------------------
12/**
13 * @category constructors
14 * @since 2.3.8
15 */
16exports.at = _.at;
17/**
18 * Lift an instance of `At` using an `Iso`.
19 *
20 * @category constructors
21 * @since 2.3.0
22 */
23var fromIso = function (iso) { return function (sia) {
24 return (0, exports.at)(function (i) { return (0, pipeable_1.pipe)(iso, _.isoAsLens, _.lensComposeLens(sia.at(i))); });
25}; };
26exports.fromIso = fromIso;
27/**
28 * @category constructors
29 * @since 2.3.7
30 */
31exports.atReadonlyRecord = _.atReadonlyRecord;
32/**
33 * @category constructors
34 * @since 2.3.7
35 */
36var atReadonlyMap = function (E) {
37 var lookupE = RM.lookup(E);
38 var deleteAtE = RM.deleteAt(E);
39 var insertAtE = RM.insertAt(E);
40 return function () {
41 return (0, exports.at)(function (key) {
42 return _.lens(function (s) { return lookupE(key, s); }, O.fold(function () { return deleteAtE(key); }, function (a) { return insertAtE(key, a); }));
43 });
44 };
45};
46exports.atReadonlyMap = atReadonlyMap;
47/**
48 * @category constructors
49 * @since 2.3.7
50 */
51var atReadonlySet = function (E) {
52 var elemE = RS.elem(E);
53 var insertE = RS.insert(E);
54 var removeE = RS.remove(E);
55 return (0, exports.at)(function (a) {
56 var insert = insertE(a);
57 var remove = removeE(a);
58 return _.lens(function (s) { return elemE(a, s); }, function (b) { return function (s) { return (b ? insert(s) : remove(s)); }; });
59 });
60};
61exports.atReadonlySet = atReadonlySet;
62// -------------------------------------------------------------------------------------
63// deprecated
64// -------------------------------------------------------------------------------------
65/**
66 * Use `atReadonlyRecord` instead.
67 *
68 * @category constructors
69 * @since 2.3.2
70 * @deprecated
71 */
72exports.atRecord = _.atReadonlyRecord;