1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | 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.composeTraversal = exports.composeOptional = exports.composePrism = exports.composeIso = exports.composeLens = exports.compose = exports.asTraversal = exports.asOptional = exports.id = exports.lens = void 0;
|
4 | var function_1 = require("fp-ts/lib/function");
|
5 | var pipeable_1 = require("fp-ts/lib/pipeable");
|
6 | var _ = require("./internal");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | exports.lens = _.lens;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | exports.id = _.lensId;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | exports.asOptional = _.lensAsOptional;
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | exports.asTraversal = _.lensAsTraversal;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | exports.compose = _.lensComposeLens;
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | exports.composeLens = exports.compose;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | exports.composeIso =
|
61 |
|
62 | (0, function_1.flow)(_.isoAsLens, exports.compose);
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | exports.composePrism = _.lensComposePrism;
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | var composeOptional = function (ab) {
|
77 | return (0, function_1.flow)(exports.asOptional, _.optionalComposeOptional(ab));
|
78 | };
|
79 | exports.composeOptional = composeOptional;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | var composeTraversal = function (ab) {
|
87 | return (0, function_1.flow)(exports.asTraversal, _.traversalComposeTraversal(ab));
|
88 | };
|
89 | exports.composeTraversal = composeTraversal;
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | var modify = function (f) { return function (sa) { return function (s) {
|
98 | var o = sa.get(s);
|
99 | var n = f(o);
|
100 | return o === n ? s : sa.set(n)(s);
|
101 | }; }; };
|
102 | exports.modify = modify;
|
103 | function modifyF(F) {
|
104 | return function (f) { return function (sa) { return function (s) { return (0, pipeable_1.pipe)(sa.get(s), f, function (fa) { return F.map(fa, function (a) { return sa.set(a)(s); }); }); }; }; };
|
105 | }
|
106 | exports.modifyF = modifyF;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | var fromNullable = function (sa) {
|
114 | return (0, exports.composePrism)(_.prismFromNullable())(sa);
|
115 | };
|
116 | exports.fromNullable = fromNullable;
|
117 | function filter(predicate) {
|
118 | return (0, exports.composePrism)(_.prismFromPredicate(predicate));
|
119 | }
|
120 | exports.filter = filter;
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | exports.prop = _.lensProp;
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | exports.props = _.lensProps;
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | exports.component = _.lensComponent;
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | var index = function (i) {
|
149 | return (0, function_1.flow)(exports.asOptional, _.optionalIndex(i));
|
150 | };
|
151 | exports.index = index;
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | var indexNonEmpty = function (i) {
|
159 | return (0, function_1.flow)(exports.asOptional, _.optionalIndexNonEmpty(i));
|
160 | };
|
161 | exports.indexNonEmpty = indexNonEmpty;
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | var key = function (key) {
|
169 | return (0, function_1.flow)(exports.asOptional, _.optionalKey(key));
|
170 | };
|
171 | exports.key = key;
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | exports.atKey = _.lensAtKey;
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | exports.some =
|
186 |
|
187 | (0, exports.composePrism)( _.prismSome());
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | exports.right =
|
195 |
|
196 | (0, exports.composePrism)( _.prismRight());
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 | exports.left =
|
204 |
|
205 | (0, exports.composePrism)( _.prismLeft());
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | function traverse(T) {
|
213 | return (0, function_1.flow)(exports.asTraversal, _.traversalTraverse(T));
|
214 | }
|
215 | exports.traverse = traverse;
|
216 | function findFirst(predicate) {
|
217 | return (0, exports.composeOptional)(_.optionalFindFirst(predicate));
|
218 | }
|
219 | exports.findFirst = findFirst;
|
220 | function findFirstNonEmpty(predicate) {
|
221 | return (0, exports.composeOptional)(_.optionalFindFirstNonEmpty(predicate));
|
222 | }
|
223 | exports.findFirstNonEmpty = findFirstNonEmpty;
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 | var imap = function (f, g) { return function (ea) {
|
232 | return imap_(ea, f, g);
|
233 | }; };
|
234 | exports.imap = imap;
|
235 |
|
236 |
|
237 |
|
238 | var imap_ = function (ea, ab, ba) { return (0, exports.lens)((0, function_1.flow)(ea.get, ab), (0, function_1.flow)(ba, ea.set)); };
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | exports.URI = 'monocle-ts/Lens';
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | exports.Invariant = {
|
249 | URI: exports.URI,
|
250 | imap: imap_
|
251 | };
|
252 |
|
253 |
|
254 |
|
255 |
|
256 | exports.Semigroupoid = {
|
257 | URI: exports.URI,
|
258 | compose: function (ab, ea) { return (0, exports.compose)(ab)(ea); }
|
259 | };
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | exports.Category = {
|
265 | URI: exports.URI,
|
266 | compose: exports.Semigroupoid.compose,
|
267 | id: exports.id
|
268 | };
|