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