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.reverse = exports.composeTraversal = exports.composeOptional = exports.composePrism = exports.composeLens = exports.composeIso = exports.compose = exports.asTraversal = exports.asOptional = exports.asPrism = exports.asLens = exports.id = exports.iso = 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.iso = _.iso;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var id = function () { return (0, exports.iso)(function_1.identity, function_1.identity); };
|
20 | exports.id = id;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | exports.asLens = _.isoAsLens;
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | exports.asPrism = _.isoAsPrism;
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | exports.asOptional = _.isoAsOptional;
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | exports.asTraversal = _.isoAsTraversal;
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | var compose = function (ab) { return function (sa) {
|
62 | return (0, exports.iso)((0, function_1.flow)(sa.get, ab.get), (0, function_1.flow)(ab.reverseGet, sa.reverseGet));
|
63 | }; };
|
64 | exports.compose = compose;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | exports.composeIso = exports.compose;
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | var composeLens = function (ab) {
|
79 | return (0, function_1.flow)(exports.asLens, _.lensComposeLens(ab));
|
80 | };
|
81 | exports.composeLens = composeLens;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | var composePrism = function (ab) {
|
89 | return (0, function_1.flow)(exports.asPrism, _.prismComposePrism(ab));
|
90 | };
|
91 | exports.composePrism = composePrism;
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var composeOptional = function (ab) {
|
99 | return (0, function_1.flow)(exports.asOptional, _.optionalComposeOptional(ab));
|
100 | };
|
101 | exports.composeOptional = composeOptional;
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | var composeTraversal = function (ab) {
|
109 | return (0, function_1.flow)(exports.asTraversal, _.traversalComposeTraversal(ab));
|
110 | };
|
111 | exports.composeTraversal = composeTraversal;
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | var reverse = function (sa) { return (0, exports.iso)(sa.reverseGet, sa.get); };
|
120 | exports.reverse = reverse;
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | var modify = function (f) { return function (sa) { return function (s) {
|
126 | return sa.reverseGet(f(sa.get(s)));
|
127 | }; }; };
|
128 | exports.modify = modify;
|
129 | function modifyF(F) {
|
130 | return function (f) { return function (sa) { return function (s) { return (0, pipeable_1.pipe)(sa.get(s), f, function (fa) { return F.map(fa, sa.reverseGet); }); }; }; };
|
131 | }
|
132 | exports.modifyF = modifyF;
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | var fromNullable = function (sa) {
|
140 | return (0, exports.composePrism)(_.prismFromNullable())(sa);
|
141 | };
|
142 | exports.fromNullable = fromNullable;
|
143 | function filter(predicate) {
|
144 | return (0, exports.composePrism)(_.prismFromPredicate(predicate));
|
145 | }
|
146 | exports.filter = filter;
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | var prop = function (prop) {
|
154 | return (0, function_1.flow)(exports.asLens, _.lensProp(prop));
|
155 | };
|
156 | exports.prop = prop;
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | var props = function () {
|
164 | var props = [];
|
165 | for (var _i = 0; _i < arguments.length; _i++) {
|
166 | props[_i] = arguments[_i];
|
167 | }
|
168 | return (0, function_1.flow)(exports.asLens, _.lensProps.apply(_, props));
|
169 | };
|
170 | exports.props = props;
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 | var component = function (prop) { return (0, function_1.flow)(exports.asLens, _.lensComponent(prop)); };
|
178 | exports.component = component;
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 | var index = function (i) {
|
186 | return (0, function_1.flow)(exports.asOptional, _.optionalIndex(i));
|
187 | };
|
188 | exports.index = index;
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 | var indexNonEmpty = function (i) {
|
196 | return (0, function_1.flow)(exports.asOptional, _.optionalIndexNonEmpty(i));
|
197 | };
|
198 | exports.indexNonEmpty = indexNonEmpty;
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 | var key = function (key) {
|
206 | return (0, function_1.flow)(exports.asOptional, _.optionalKey(key));
|
207 | };
|
208 | exports.key = key;
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | var atKey = function (key) {
|
216 | return (0, function_1.flow)(exports.asLens, _.lensAtKey(key));
|
217 | };
|
218 | exports.atKey = atKey;
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 | exports.some =
|
226 |
|
227 | (0, exports.composePrism)( _.prismSome());
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 | exports.right =
|
235 |
|
236 | (0, exports.composePrism)( _.prismRight());
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | exports.left =
|
244 |
|
245 | (0, exports.composePrism)( _.prismLeft());
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 | function traverse(T) {
|
253 | return (0, function_1.flow)(exports.asTraversal, _.traversalTraverse(T));
|
254 | }
|
255 | exports.traverse = traverse;
|
256 | function findFirst(predicate) {
|
257 | return (0, exports.composeOptional)(_.optionalFindFirst(predicate));
|
258 | }
|
259 | exports.findFirst = findFirst;
|
260 | function findFirstNonEmpty(predicate) {
|
261 | return (0, exports.composeOptional)(_.optionalFindFirstNonEmpty(predicate));
|
262 | }
|
263 | exports.findFirstNonEmpty = findFirstNonEmpty;
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 | var imap = function (f, g) { return function (ea) {
|
272 | return imap_(ea, f, g);
|
273 | }; };
|
274 | exports.imap = imap;
|
275 |
|
276 |
|
277 |
|
278 | var imap_ = function (ea, ab, ba) { return (0, exports.iso)((0, function_1.flow)(ea.get, ab), (0, function_1.flow)(ba, ea.reverseGet)); };
|
279 |
|
280 |
|
281 |
|
282 |
|
283 | exports.URI = 'monocle-ts/Iso';
|
284 |
|
285 |
|
286 |
|
287 |
|
288 | exports.Invariant = {
|
289 | URI: exports.URI,
|
290 | imap: imap_
|
291 | };
|
292 |
|
293 |
|
294 |
|
295 |
|
296 | exports.Semigroupoid = {
|
297 | URI: exports.URI,
|
298 | compose: function (ab, ea) { return (0, exports.compose)(ab)(ea); }
|
299 | };
|
300 |
|
301 |
|
302 |
|
303 |
|
304 | exports.Category = {
|
305 | URI: exports.URI,
|
306 | compose: exports.Semigroupoid.compose,
|
307 | id: exports.id
|
308 | };
|