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