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