rambda 7.2.1 → 7.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.md +1431 -3264
- package/dist/rambda.js +83 -422
- package/dist/rambda.mjs +89 -433
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +290 -229
- package/index.d.ts +290 -229
- package/package.json +38 -33
- package/rambda.js +187 -0
- package/src/_internals/constants.js +1 -0
- package/src/_internals/isArray.js +1 -0
- package/src/_internals/isFalsy.js +2 -2
- package/src/_internals/isInteger.js +5 -0
- package/src/_internals/isIterable.js +5 -0
- package/src/_internals/isObject.js +1 -1
- package/src/_internals/isTruthy.js +2 -2
- package/src/_internals/keys.js +1 -0
- package/src/_internals/{_objectIs.js → objectIs.js} +2 -2
- package/src/applySpec.js +3 -3
- package/src/assocPath.js +7 -7
- package/src/clone.js +2 -2
- package/src/count.js +2 -2
- package/src/dropLastWhile.js +2 -2
- package/src/dropRepeats.js +2 -2
- package/src/dropRepeatsWith.js +2 -2
- package/src/dropWhile.js +2 -2
- package/src/endsWith.js +2 -2
- package/src/equals.js +3 -15
- package/src/evolve.js +1 -1
- package/src/filter.js +2 -2
- package/src/flatten.js +2 -2
- package/src/forEach.js +6 -6
- package/src/groupWith.js +2 -2
- package/src/identical.js +2 -2
- package/src/includes.js +2 -2
- package/src/isPromise.js +1 -1
- package/src/length.js +2 -2
- package/src/map.js +8 -7
- package/src/mathMod.js +2 -2
- package/src/merge.js +1 -1
- package/src/mergeDeepRight.js +2 -1
- package/src/mergeRight.js +2 -1
- package/src/modify.js +23 -0
- package/src/modifyPath.js +2 -2
- package/src/nop.js +1 -0
- package/src/partialObject.js +1 -11
- package/src/partition.js +2 -2
- package/src/props.js +2 -2
- package/src/reduce.js +2 -3
- package/src/splitAt.js +2 -2
- package/src/startsWith.js +2 -2
- package/src/takeLastWhile.js +2 -2
- package/src/takeWhile.js +2 -2
- package/src/test.js +1 -1
- package/src/times.js +2 -1
- package/src/transpose.js +2 -2
- package/src/unwind.js +4 -3
- package/src/update.js +1 -1
- package/src/where.js +1 -0
- package/src/_internals/_isArray.js +0 -1
- package/src/_internals/_isInteger.js +0 -5
- package/src/_internals/_keys.js +0 -1
package/dist/rambda.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
function F() {
|
|
6
4
|
return false;
|
|
7
5
|
}
|
|
@@ -28,31 +26,25 @@ function adjustFn(index, replaceFn, list) {
|
|
|
28
26
|
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
29
27
|
return clone;
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
const adjust = curry(adjustFn);
|
|
33
30
|
|
|
34
31
|
function all(predicate, list) {
|
|
35
32
|
if (arguments.length === 1) return _list => all(predicate, _list);
|
|
36
|
-
|
|
37
33
|
for (let i = 0; i < list.length; i++) {
|
|
38
34
|
if (!predicate(list[i])) return false;
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
return true;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
39
|
function allPass(predicates) {
|
|
45
40
|
return (...input) => {
|
|
46
41
|
let counter = 0;
|
|
47
|
-
|
|
48
42
|
while (counter < predicates.length) {
|
|
49
43
|
if (!predicates[counter](...input)) {
|
|
50
44
|
return false;
|
|
51
45
|
}
|
|
52
|
-
|
|
53
46
|
counter++;
|
|
54
47
|
}
|
|
55
|
-
|
|
56
48
|
return true;
|
|
57
49
|
};
|
|
58
50
|
}
|
|
@@ -69,30 +61,24 @@ function and(a, b) {
|
|
|
69
61
|
function any(predicate, list) {
|
|
70
62
|
if (arguments.length === 1) return _list => any(predicate, _list);
|
|
71
63
|
let counter = 0;
|
|
72
|
-
|
|
73
64
|
while (counter < list.length) {
|
|
74
65
|
if (predicate(list[counter], counter)) {
|
|
75
66
|
return true;
|
|
76
67
|
}
|
|
77
|
-
|
|
78
68
|
counter++;
|
|
79
69
|
}
|
|
80
|
-
|
|
81
70
|
return false;
|
|
82
71
|
}
|
|
83
72
|
|
|
84
73
|
function anyPass(predicates) {
|
|
85
74
|
return (...input) => {
|
|
86
75
|
let counter = 0;
|
|
87
|
-
|
|
88
76
|
while (counter < predicates.length) {
|
|
89
77
|
if (predicates[counter](...input)) {
|
|
90
78
|
return true;
|
|
91
79
|
}
|
|
92
|
-
|
|
93
80
|
counter++;
|
|
94
81
|
}
|
|
95
|
-
|
|
96
82
|
return false;
|
|
97
83
|
};
|
|
98
84
|
}
|
|
@@ -109,42 +95,36 @@ function apply(fn, args) {
|
|
|
109
95
|
if (arguments.length === 1) {
|
|
110
96
|
return _args => apply(fn, _args);
|
|
111
97
|
}
|
|
112
|
-
|
|
113
98
|
return fn.apply(this, args);
|
|
114
99
|
}
|
|
115
100
|
|
|
116
|
-
const
|
|
101
|
+
const {
|
|
102
|
+
isArray
|
|
103
|
+
} = Array;
|
|
117
104
|
|
|
118
105
|
function __findHighestArity(spec, max = 0) {
|
|
119
106
|
for (const key in spec) {
|
|
120
107
|
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
|
121
|
-
|
|
122
108
|
if (typeof spec[key] === 'object') {
|
|
123
109
|
max = Math.max(max, __findHighestArity(spec[key]));
|
|
124
110
|
}
|
|
125
|
-
|
|
126
111
|
if (typeof spec[key] === 'function') {
|
|
127
112
|
max = Math.max(max, spec[key].length);
|
|
128
113
|
}
|
|
129
114
|
}
|
|
130
|
-
|
|
131
115
|
return max;
|
|
132
116
|
}
|
|
133
|
-
|
|
134
117
|
function __filterUndefined() {
|
|
135
118
|
const defined = [];
|
|
136
119
|
let i = 0;
|
|
137
120
|
const l = arguments.length;
|
|
138
|
-
|
|
139
121
|
while (i < l) {
|
|
140
122
|
if (typeof arguments[i] === 'undefined') break;
|
|
141
123
|
defined[i] = arguments[i];
|
|
142
124
|
i++;
|
|
143
125
|
}
|
|
144
|
-
|
|
145
126
|
return defined;
|
|
146
127
|
}
|
|
147
|
-
|
|
148
128
|
function __applySpecWithArity(spec, arity, cache) {
|
|
149
129
|
const remaining = arity - cache.length;
|
|
150
130
|
if (remaining === 1) return x => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x));
|
|
@@ -152,52 +132,39 @@ function __applySpecWithArity(spec, arity, cache) {
|
|
|
152
132
|
if (remaining === 3) return (x, y, z) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z));
|
|
153
133
|
if (remaining === 4) return (x, y, z, a) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, x, y, z, a));
|
|
154
134
|
if (remaining > 4) return (...args) => __applySpecWithArity(spec, arity, __filterUndefined(...cache, ...args));
|
|
155
|
-
|
|
156
|
-
if (_isArray(spec)) {
|
|
135
|
+
if (isArray(spec)) {
|
|
157
136
|
const ret = [];
|
|
158
137
|
let i = 0;
|
|
159
138
|
const l = spec.length;
|
|
160
|
-
|
|
161
139
|
for (; i < l; i++) {
|
|
162
|
-
if (typeof spec[i] === 'object' ||
|
|
140
|
+
if (typeof spec[i] === 'object' || isArray(spec[i])) {
|
|
163
141
|
ret[i] = __applySpecWithArity(spec[i], arity, cache);
|
|
164
142
|
}
|
|
165
|
-
|
|
166
143
|
if (typeof spec[i] === 'function') {
|
|
167
144
|
ret[i] = spec[i](...cache);
|
|
168
145
|
}
|
|
169
146
|
}
|
|
170
|
-
|
|
171
147
|
return ret;
|
|
172
148
|
}
|
|
173
|
-
|
|
174
149
|
const ret = {};
|
|
175
|
-
|
|
176
150
|
for (const key in spec) {
|
|
177
151
|
if (spec.hasOwnProperty(key) === false || key === 'constructor') continue;
|
|
178
|
-
|
|
179
152
|
if (typeof spec[key] === 'object') {
|
|
180
153
|
ret[key] = __applySpecWithArity(spec[key], arity, cache);
|
|
181
154
|
continue;
|
|
182
155
|
}
|
|
183
|
-
|
|
184
156
|
if (typeof spec[key] === 'function') {
|
|
185
157
|
ret[key] = spec[key](...cache);
|
|
186
158
|
}
|
|
187
159
|
}
|
|
188
|
-
|
|
189
160
|
return ret;
|
|
190
161
|
}
|
|
191
|
-
|
|
192
162
|
function applySpec(spec, ...args) {
|
|
193
163
|
const arity = __findHighestArity(spec);
|
|
194
|
-
|
|
195
164
|
if (arity === 0) {
|
|
196
165
|
return () => ({});
|
|
197
166
|
}
|
|
198
|
-
|
|
199
167
|
const toReturn = __applySpecWithArity(spec, arity, args);
|
|
200
|
-
|
|
201
168
|
return toReturn;
|
|
202
169
|
}
|
|
203
170
|
|
|
@@ -206,38 +173,31 @@ function assocFn(prop, newValue, obj) {
|
|
|
206
173
|
[prop]: newValue
|
|
207
174
|
});
|
|
208
175
|
}
|
|
209
|
-
|
|
210
176
|
const assoc = curry(assocFn);
|
|
211
177
|
|
|
212
178
|
function _isInteger(n) {
|
|
213
179
|
return n << 0 === n;
|
|
214
180
|
}
|
|
215
|
-
|
|
181
|
+
const isInteger = Number.isInteger || _isInteger;
|
|
216
182
|
|
|
217
183
|
function assocPathFn(path, newValue, input) {
|
|
218
|
-
const pathArrValue = typeof path === 'string' ? path.split('.').map(x =>
|
|
219
|
-
|
|
184
|
+
const pathArrValue = typeof path === 'string' ? path.split('.').map(x => isInteger(Number(x)) ? Number(x) : x) : path;
|
|
220
185
|
if (pathArrValue.length === 0) {
|
|
221
186
|
return newValue;
|
|
222
187
|
}
|
|
223
|
-
|
|
224
188
|
const index = pathArrValue[0];
|
|
225
|
-
|
|
226
189
|
if (pathArrValue.length > 1) {
|
|
227
190
|
const condition = typeof input !== 'object' || input === null || !input.hasOwnProperty(index);
|
|
228
|
-
const
|
|
229
|
-
newValue = assocPathFn(Array.prototype.slice.call(pathArrValue, 1), newValue,
|
|
191
|
+
const nextInput = condition ? isInteger(pathArrValue[1]) ? [] : {} : input[index];
|
|
192
|
+
newValue = assocPathFn(Array.prototype.slice.call(pathArrValue, 1), newValue, nextInput);
|
|
230
193
|
}
|
|
231
|
-
|
|
232
|
-
if (_isInteger(index) && _isArray(input)) {
|
|
194
|
+
if (isInteger(index) && isArray(input)) {
|
|
233
195
|
const arr = cloneList(input);
|
|
234
196
|
arr[index] = newValue;
|
|
235
197
|
return arr;
|
|
236
198
|
}
|
|
237
|
-
|
|
238
199
|
return assoc(index, newValue, input);
|
|
239
200
|
}
|
|
240
|
-
|
|
241
201
|
const assocPath = curry(assocPathFn);
|
|
242
202
|
|
|
243
203
|
function _curryN(n, cache, fn) {
|
|
@@ -247,88 +207,71 @@ function _curryN(n, cache, fn) {
|
|
|
247
207
|
const cl = cache.length;
|
|
248
208
|
const al = arguments.length;
|
|
249
209
|
const args = new Array(cl + al);
|
|
250
|
-
|
|
251
210
|
while (ci < cl) {
|
|
252
211
|
args[ci] = cache[ci];
|
|
253
212
|
ci++;
|
|
254
213
|
}
|
|
255
|
-
|
|
256
214
|
while (ai < al) {
|
|
257
215
|
args[cl + ai] = arguments[ai];
|
|
258
216
|
ai++;
|
|
259
217
|
}
|
|
260
|
-
|
|
261
218
|
const remaining = n - args.length;
|
|
262
219
|
return args.length >= n ? fn.apply(this, args) : _arity$1(remaining, _curryN(n, args, fn));
|
|
263
220
|
};
|
|
264
221
|
}
|
|
265
|
-
|
|
266
222
|
function _arity$1(n, fn) {
|
|
267
223
|
switch (n) {
|
|
268
224
|
case 0:
|
|
269
225
|
return function () {
|
|
270
226
|
return fn.apply(this, arguments);
|
|
271
227
|
};
|
|
272
|
-
|
|
273
228
|
case 1:
|
|
274
229
|
return function (_1) {
|
|
275
230
|
return fn.apply(this, arguments);
|
|
276
231
|
};
|
|
277
|
-
|
|
278
232
|
case 2:
|
|
279
233
|
return function (_1, _2) {
|
|
280
234
|
return fn.apply(this, arguments);
|
|
281
235
|
};
|
|
282
|
-
|
|
283
236
|
case 3:
|
|
284
237
|
return function (_1, _2, _3) {
|
|
285
238
|
return fn.apply(this, arguments);
|
|
286
239
|
};
|
|
287
|
-
|
|
288
240
|
case 4:
|
|
289
241
|
return function (_1, _2, _3, _4) {
|
|
290
242
|
return fn.apply(this, arguments);
|
|
291
243
|
};
|
|
292
|
-
|
|
293
244
|
case 5:
|
|
294
245
|
return function (_1, _2, _3, _4, _5) {
|
|
295
246
|
return fn.apply(this, arguments);
|
|
296
247
|
};
|
|
297
|
-
|
|
298
248
|
case 6:
|
|
299
249
|
return function (_1, _2, _3, _4, _5, _6) {
|
|
300
250
|
return fn.apply(this, arguments);
|
|
301
251
|
};
|
|
302
|
-
|
|
303
252
|
case 7:
|
|
304
253
|
return function (_1, _2, _3, _4, _5, _6, _7) {
|
|
305
254
|
return fn.apply(this, arguments);
|
|
306
255
|
};
|
|
307
|
-
|
|
308
256
|
case 8:
|
|
309
257
|
return function (_1, _2, _3, _4, _5, _6, _7, _8) {
|
|
310
258
|
return fn.apply(this, arguments);
|
|
311
259
|
};
|
|
312
|
-
|
|
313
260
|
case 9:
|
|
314
261
|
return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
|
|
315
262
|
return fn.apply(this, arguments);
|
|
316
263
|
};
|
|
317
|
-
|
|
318
264
|
default:
|
|
319
265
|
return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
|
|
320
266
|
return fn.apply(this, arguments);
|
|
321
267
|
};
|
|
322
268
|
}
|
|
323
269
|
}
|
|
324
|
-
|
|
325
270
|
function curryN(n, fn) {
|
|
326
271
|
if (arguments.length === 1) return _fn => curryN(n, _fn);
|
|
327
|
-
|
|
328
272
|
if (n > 10) {
|
|
329
273
|
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
|
330
274
|
}
|
|
331
|
-
|
|
332
275
|
return _arity$1(n, _curryN(n, [], fn));
|
|
333
276
|
}
|
|
334
277
|
|
|
@@ -336,7 +279,6 @@ function bind(fn, thisObj) {
|
|
|
336
279
|
if (arguments.length === 1) {
|
|
337
280
|
return _thisObj => bind(fn, _thisObj);
|
|
338
281
|
}
|
|
339
|
-
|
|
340
282
|
return curryN(fn.length, (...args) => fn.apply(thisObj, args));
|
|
341
283
|
}
|
|
342
284
|
|
|
@@ -349,7 +291,6 @@ function chain(fn, list) {
|
|
|
349
291
|
if (arguments.length === 1) {
|
|
350
292
|
return _list => chain(fn, _list);
|
|
351
293
|
}
|
|
352
|
-
|
|
353
294
|
return [].concat(...list.map(fn));
|
|
354
295
|
}
|
|
355
296
|
|
|
@@ -357,23 +298,19 @@ function clampFn(min, max, input) {
|
|
|
357
298
|
if (min > max) {
|
|
358
299
|
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
359
300
|
}
|
|
360
|
-
|
|
361
301
|
if (input >= min && input <= max) return input;
|
|
362
302
|
if (input > max) return max;
|
|
363
303
|
if (input < min) return min;
|
|
364
304
|
}
|
|
365
|
-
|
|
366
305
|
const clamp = curry(clampFn);
|
|
367
306
|
|
|
368
307
|
function clone(input) {
|
|
369
|
-
const out =
|
|
308
|
+
const out = isArray(input) ? Array(input.length) : {};
|
|
370
309
|
if (input && input.getTime) return new Date(input.getTime());
|
|
371
|
-
|
|
372
310
|
for (const key in input) {
|
|
373
311
|
const v = input[key];
|
|
374
312
|
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
375
313
|
}
|
|
376
|
-
|
|
377
314
|
return out;
|
|
378
315
|
}
|
|
379
316
|
|
|
@@ -381,33 +318,24 @@ function complement(fn) {
|
|
|
381
318
|
return (...input) => !fn(...input);
|
|
382
319
|
}
|
|
383
320
|
|
|
384
|
-
const _keys = Object.keys;
|
|
385
|
-
|
|
386
321
|
class ReduceStopper {
|
|
387
322
|
constructor(value) {
|
|
388
323
|
this.value = value;
|
|
389
324
|
}
|
|
390
|
-
|
|
391
325
|
}
|
|
392
|
-
|
|
393
326
|
function reduceFn(reducer, acc, list) {
|
|
394
|
-
if (!
|
|
327
|
+
if (!isArray(list)) {
|
|
395
328
|
throw new TypeError('reduce: list must be array or iterable');
|
|
396
329
|
}
|
|
397
|
-
|
|
398
330
|
let index = 0;
|
|
399
331
|
const len = list.length;
|
|
400
|
-
|
|
401
332
|
while (index < len) {
|
|
402
333
|
acc = reducer(acc, list[index], index, list);
|
|
403
|
-
|
|
404
334
|
if (acc instanceof ReduceStopper) {
|
|
405
335
|
return acc.value;
|
|
406
336
|
}
|
|
407
|
-
|
|
408
337
|
index++;
|
|
409
338
|
}
|
|
410
|
-
|
|
411
339
|
return acc;
|
|
412
340
|
}
|
|
413
341
|
const reduce = curry(reduceFn);
|
|
@@ -419,57 +347,46 @@ function _arity(n, fn) {
|
|
|
419
347
|
return function () {
|
|
420
348
|
return fn.apply(this, arguments);
|
|
421
349
|
};
|
|
422
|
-
|
|
423
350
|
case 1:
|
|
424
351
|
return function (a0) {
|
|
425
352
|
return fn.apply(this, arguments);
|
|
426
353
|
};
|
|
427
|
-
|
|
428
354
|
case 2:
|
|
429
355
|
return function (a0, a1) {
|
|
430
356
|
return fn.apply(this, arguments);
|
|
431
357
|
};
|
|
432
|
-
|
|
433
358
|
case 3:
|
|
434
359
|
return function (a0, a1, a2) {
|
|
435
360
|
return fn.apply(this, arguments);
|
|
436
361
|
};
|
|
437
|
-
|
|
438
362
|
case 4:
|
|
439
363
|
return function (a0, a1, a2, a3) {
|
|
440
364
|
return fn.apply(this, arguments);
|
|
441
365
|
};
|
|
442
|
-
|
|
443
366
|
case 5:
|
|
444
367
|
return function (a0, a1, a2, a3, a4) {
|
|
445
368
|
return fn.apply(this, arguments);
|
|
446
369
|
};
|
|
447
|
-
|
|
448
370
|
case 6:
|
|
449
371
|
return function (a0, a1, a2, a3, a4, a5) {
|
|
450
372
|
return fn.apply(this, arguments);
|
|
451
373
|
};
|
|
452
|
-
|
|
453
374
|
case 7:
|
|
454
375
|
return function (a0, a1, a2, a3, a4, a5, a6) {
|
|
455
376
|
return fn.apply(this, arguments);
|
|
456
377
|
};
|
|
457
|
-
|
|
458
378
|
case 8:
|
|
459
379
|
return function (a0, a1, a2, a3, a4, a5, a6, a7) {
|
|
460
380
|
return fn.apply(this, arguments);
|
|
461
381
|
};
|
|
462
|
-
|
|
463
382
|
case 9:
|
|
464
383
|
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
|
|
465
384
|
return fn.apply(this, arguments);
|
|
466
385
|
};
|
|
467
|
-
|
|
468
386
|
case 10:
|
|
469
387
|
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
470
388
|
return fn.apply(this, arguments);
|
|
471
389
|
};
|
|
472
|
-
|
|
473
390
|
default:
|
|
474
391
|
throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
|
|
475
392
|
}
|
|
@@ -483,7 +400,6 @@ function pipe() {
|
|
|
483
400
|
if (arguments.length === 0) {
|
|
484
401
|
throw new Error('pipe requires at least one argument');
|
|
485
402
|
}
|
|
486
|
-
|
|
487
403
|
return _arity(arguments[0].length, reduceFn(_pipe, arguments[0], Array.prototype.slice.call(arguments, 1, Infinity)));
|
|
488
404
|
}
|
|
489
405
|
|
|
@@ -491,7 +407,6 @@ function compose() {
|
|
|
491
407
|
if (arguments.length === 0) {
|
|
492
408
|
throw new Error('compose requires at least one argument');
|
|
493
409
|
}
|
|
494
|
-
|
|
495
410
|
return pipe.apply(this, Array.prototype.slice.call(arguments, 0).reverse());
|
|
496
411
|
}
|
|
497
412
|
|
|
@@ -514,46 +429,43 @@ function cond(conditions) {
|
|
|
514
429
|
};
|
|
515
430
|
}
|
|
516
431
|
|
|
432
|
+
const INCORRECT_ITERABLE_INPUT = 'Incorrect iterable input';
|
|
433
|
+
|
|
434
|
+
const {
|
|
435
|
+
keys: keys$1
|
|
436
|
+
} = Object;
|
|
437
|
+
|
|
517
438
|
function mapArray(fn, list, isIndexed = false) {
|
|
518
439
|
let index = 0;
|
|
519
440
|
const willReturn = Array(list.length);
|
|
520
|
-
|
|
521
441
|
while (index < list.length) {
|
|
522
442
|
willReturn[index] = isIndexed ? fn(list[index], index) : fn(list[index]);
|
|
523
443
|
index++;
|
|
524
444
|
}
|
|
525
|
-
|
|
526
445
|
return willReturn;
|
|
527
446
|
}
|
|
528
447
|
function mapObject(fn, obj) {
|
|
529
448
|
if (arguments.length === 1) {
|
|
530
449
|
return _obj => mapObject(fn, _obj);
|
|
531
450
|
}
|
|
532
|
-
|
|
533
451
|
let index = 0;
|
|
534
|
-
|
|
535
|
-
const
|
|
536
|
-
|
|
537
|
-
const len = keys.length;
|
|
452
|
+
const objKeys = keys$1(obj);
|
|
453
|
+
const len = objKeys.length;
|
|
538
454
|
const willReturn = {};
|
|
539
|
-
|
|
540
455
|
while (index < len) {
|
|
541
|
-
const key =
|
|
456
|
+
const key = objKeys[index];
|
|
542
457
|
willReturn[key] = fn(obj[key], key, obj);
|
|
543
458
|
index++;
|
|
544
459
|
}
|
|
545
|
-
|
|
546
460
|
return willReturn;
|
|
547
461
|
}
|
|
548
462
|
const mapObjIndexed = mapObject;
|
|
549
463
|
function map(fn, iterable) {
|
|
550
464
|
if (arguments.length === 1) return _iterable => map(fn, _iterable);
|
|
551
|
-
|
|
552
465
|
if (!iterable) {
|
|
553
|
-
throw new Error(
|
|
466
|
+
throw new Error(INCORRECT_ITERABLE_INPUT);
|
|
554
467
|
}
|
|
555
|
-
|
|
556
|
-
if (_isArray(iterable)) return mapArray(fn, iterable);
|
|
468
|
+
if (isArray(iterable)) return mapArray(fn, iterable);
|
|
557
469
|
return mapObject(fn, iterable);
|
|
558
470
|
}
|
|
559
471
|
|
|
@@ -574,8 +486,7 @@ function count(predicate, list) {
|
|
|
574
486
|
if (arguments.length === 1) {
|
|
575
487
|
return _list => count(predicate, _list);
|
|
576
488
|
}
|
|
577
|
-
|
|
578
|
-
if (!_isArray(list)) return 0;
|
|
489
|
+
if (!isArray(list)) return 0;
|
|
579
490
|
return list.filter(x => predicate(x)).length;
|
|
580
491
|
}
|
|
581
492
|
|
|
@@ -583,11 +494,9 @@ function countBy(fn, list) {
|
|
|
583
494
|
if (arguments.length === 1) {
|
|
584
495
|
return _list => countBy(fn, _list);
|
|
585
496
|
}
|
|
586
|
-
|
|
587
497
|
const willReturn = {};
|
|
588
498
|
list.forEach(item => {
|
|
589
499
|
const key = fn(item);
|
|
590
|
-
|
|
591
500
|
if (!willReturn[key]) {
|
|
592
501
|
willReturn[key] = 1;
|
|
593
502
|
} else {
|
|
@@ -602,12 +511,10 @@ const dec = x => x - 1;
|
|
|
602
511
|
function isFalsy(input) {
|
|
603
512
|
return input === undefined || input === null || Number.isNaN(input) === true;
|
|
604
513
|
}
|
|
605
|
-
|
|
606
514
|
function defaultTo(defaultArgument, input) {
|
|
607
515
|
if (arguments.length === 1) {
|
|
608
516
|
return _input => defaultTo(defaultArgument, _input);
|
|
609
517
|
}
|
|
610
|
-
|
|
611
518
|
return isFalsy(input) ? defaultArgument : input;
|
|
612
519
|
}
|
|
613
520
|
|
|
@@ -619,16 +526,14 @@ function type(input) {
|
|
|
619
526
|
} else if (Number.isNaN(input)) {
|
|
620
527
|
return 'NaN';
|
|
621
528
|
}
|
|
622
|
-
|
|
623
529
|
const typeResult = Object.prototype.toString.call(input).slice(8, -1);
|
|
624
530
|
return typeResult === 'AsyncFunction' ? 'Promise' : typeResult;
|
|
625
531
|
}
|
|
626
532
|
|
|
627
533
|
function _lastIndexOf(valueToFind, list) {
|
|
628
|
-
if (!
|
|
534
|
+
if (!isArray(list)) {
|
|
629
535
|
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
630
536
|
}
|
|
631
|
-
|
|
632
537
|
const typeOfValue = type(valueToFind);
|
|
633
538
|
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.lastIndexOf(valueToFind);
|
|
634
539
|
const {
|
|
@@ -636,20 +541,17 @@ function _lastIndexOf(valueToFind, list) {
|
|
|
636
541
|
} = list;
|
|
637
542
|
let index = length;
|
|
638
543
|
let foundIndex = -1;
|
|
639
|
-
|
|
640
544
|
while (--index > -1 && foundIndex === -1) {
|
|
641
545
|
if (equals(list[index], valueToFind)) {
|
|
642
546
|
foundIndex = index;
|
|
643
547
|
}
|
|
644
548
|
}
|
|
645
|
-
|
|
646
549
|
return foundIndex;
|
|
647
550
|
}
|
|
648
551
|
function _indexOf(valueToFind, list) {
|
|
649
|
-
if (!
|
|
552
|
+
if (!isArray(list)) {
|
|
650
553
|
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
651
554
|
}
|
|
652
|
-
|
|
653
555
|
const typeOfValue = type(valueToFind);
|
|
654
556
|
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.indexOf(valueToFind);
|
|
655
557
|
let index = -1;
|
|
@@ -657,85 +559,64 @@ function _indexOf(valueToFind, list) {
|
|
|
657
559
|
const {
|
|
658
560
|
length
|
|
659
561
|
} = list;
|
|
660
|
-
|
|
661
562
|
while (++index < length && foundIndex === -1) {
|
|
662
563
|
if (equals(list[index], valueToFind)) {
|
|
663
564
|
foundIndex = index;
|
|
664
565
|
}
|
|
665
566
|
}
|
|
666
|
-
|
|
667
567
|
return foundIndex;
|
|
668
568
|
}
|
|
669
|
-
|
|
670
569
|
function _arrayFromIterator(iter) {
|
|
671
570
|
const list = [];
|
|
672
571
|
let next;
|
|
673
|
-
|
|
674
572
|
while (!(next = iter.next()).done) {
|
|
675
573
|
list.push(next.value);
|
|
676
574
|
}
|
|
677
|
-
|
|
678
575
|
return list;
|
|
679
576
|
}
|
|
680
|
-
|
|
681
577
|
function _equalsSets(a, b) {
|
|
682
578
|
if (a.size !== b.size) {
|
|
683
579
|
return false;
|
|
684
580
|
}
|
|
685
|
-
|
|
686
581
|
const aList = _arrayFromIterator(a.values());
|
|
687
|
-
|
|
688
582
|
const bList = _arrayFromIterator(b.values());
|
|
689
|
-
|
|
690
583
|
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1);
|
|
691
584
|
return filtered.length === 0;
|
|
692
585
|
}
|
|
693
|
-
|
|
694
586
|
function parseError(maybeError) {
|
|
695
587
|
const typeofError = maybeError.__proto__.toString();
|
|
696
|
-
|
|
697
588
|
if (!['Error', 'TypeError'].includes(typeofError)) return [];
|
|
698
589
|
return [typeofError, maybeError.message];
|
|
699
590
|
}
|
|
700
|
-
|
|
701
591
|
function parseDate(maybeDate) {
|
|
702
592
|
if (!maybeDate.toDateString) return [false];
|
|
703
593
|
return [true, maybeDate.getTime()];
|
|
704
594
|
}
|
|
705
|
-
|
|
706
595
|
function parseRegex(maybeRegex) {
|
|
707
596
|
if (maybeRegex.constructor !== RegExp) return [false];
|
|
708
597
|
return [true, maybeRegex.toString()];
|
|
709
598
|
}
|
|
710
|
-
|
|
711
599
|
function equals(a, b) {
|
|
712
600
|
if (arguments.length === 1) return _b => equals(a, _b);
|
|
713
601
|
const aType = type(a);
|
|
714
602
|
if (aType !== type(b)) return false;
|
|
715
|
-
|
|
716
603
|
if (aType === 'Function') {
|
|
717
604
|
return a.name === undefined ? false : a.name === b.name;
|
|
718
605
|
}
|
|
719
|
-
|
|
720
606
|
if (['NaN', 'Undefined', 'Null'].includes(aType)) return true;
|
|
721
|
-
|
|
722
607
|
if (aType === 'Number') {
|
|
723
608
|
if (Object.is(-0, a) !== Object.is(-0, b)) return false;
|
|
724
609
|
return a.toString() === b.toString();
|
|
725
610
|
}
|
|
726
|
-
|
|
727
611
|
if (['String', 'Boolean'].includes(aType)) {
|
|
728
612
|
return a.toString() === b.toString();
|
|
729
613
|
}
|
|
730
|
-
|
|
731
614
|
if (aType === 'Array') {
|
|
732
615
|
const aClone = Array.from(a);
|
|
733
616
|
const bClone = Array.from(b);
|
|
734
|
-
|
|
735
617
|
if (aClone.toString() !== bClone.toString()) {
|
|
736
618
|
return false;
|
|
737
619
|
}
|
|
738
|
-
|
|
739
620
|
let loopArrayFlag = true;
|
|
740
621
|
aClone.forEach((aCloneInstance, aCloneIndex) => {
|
|
741
622
|
if (loopArrayFlag) {
|
|
@@ -746,45 +627,34 @@ function equals(a, b) {
|
|
|
746
627
|
});
|
|
747
628
|
return loopArrayFlag;
|
|
748
629
|
}
|
|
749
|
-
|
|
750
630
|
const aRegex = parseRegex(a);
|
|
751
631
|
const bRegex = parseRegex(b);
|
|
752
|
-
|
|
753
632
|
if (aRegex[0]) {
|
|
754
633
|
return bRegex[0] ? aRegex[1] === bRegex[1] : false;
|
|
755
634
|
} else if (bRegex[0]) return false;
|
|
756
|
-
|
|
757
635
|
const aDate = parseDate(a);
|
|
758
636
|
const bDate = parseDate(b);
|
|
759
|
-
|
|
760
637
|
if (aDate[0]) {
|
|
761
638
|
return bDate[0] ? aDate[1] === bDate[1] : false;
|
|
762
639
|
} else if (bDate[0]) return false;
|
|
763
|
-
|
|
764
640
|
const aError = parseError(a);
|
|
765
641
|
const bError = parseError(b);
|
|
766
|
-
|
|
767
642
|
if (aError[0]) {
|
|
768
643
|
return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
|
769
644
|
}
|
|
770
|
-
|
|
771
645
|
if (aType === 'Set') {
|
|
772
646
|
return _equalsSets(a, b);
|
|
773
647
|
}
|
|
774
|
-
|
|
775
648
|
if (aType === 'Object') {
|
|
776
649
|
const aKeys = Object.keys(a);
|
|
777
|
-
|
|
778
650
|
if (aKeys.length !== Object.keys(b).length) {
|
|
779
651
|
return false;
|
|
780
652
|
}
|
|
781
|
-
|
|
782
653
|
let loopObjectFlag = true;
|
|
783
654
|
aKeys.forEach(aKeyInstance => {
|
|
784
655
|
if (loopObjectFlag) {
|
|
785
656
|
const aValue = a[aKeyInstance];
|
|
786
657
|
const bValue = b[aKeyInstance];
|
|
787
|
-
|
|
788
658
|
if (aValue !== bValue && !equals(aValue, bValue)) {
|
|
789
659
|
loopObjectFlag = false;
|
|
790
660
|
}
|
|
@@ -792,22 +662,18 @@ function equals(a, b) {
|
|
|
792
662
|
});
|
|
793
663
|
return loopObjectFlag;
|
|
794
664
|
}
|
|
795
|
-
|
|
796
665
|
return false;
|
|
797
666
|
}
|
|
798
667
|
|
|
799
668
|
function includes(valueToFind, iterable) {
|
|
800
669
|
if (arguments.length === 1) return _iterable => includes(valueToFind, _iterable);
|
|
801
|
-
|
|
802
670
|
if (typeof iterable === 'string') {
|
|
803
671
|
return iterable.includes(valueToFind);
|
|
804
672
|
}
|
|
805
|
-
|
|
806
673
|
if (!iterable) {
|
|
807
674
|
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`);
|
|
808
675
|
}
|
|
809
|
-
|
|
810
|
-
if (!_isArray(iterable)) return false;
|
|
676
|
+
if (!isArray(iterable)) return false;
|
|
811
677
|
return _indexOf(valueToFind, iterable) > -1;
|
|
812
678
|
}
|
|
813
679
|
|
|
@@ -816,38 +682,30 @@ class _Set {
|
|
|
816
682
|
this.set = new Set();
|
|
817
683
|
this.items = {};
|
|
818
684
|
}
|
|
819
|
-
|
|
820
685
|
checkUniqueness(item) {
|
|
821
686
|
const type$1 = type(item);
|
|
822
|
-
|
|
823
687
|
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
824
688
|
if (type$1 in this.items) {
|
|
825
689
|
return false;
|
|
826
690
|
}
|
|
827
|
-
|
|
828
691
|
this.items[type$1] = true;
|
|
829
692
|
return true;
|
|
830
693
|
}
|
|
831
|
-
|
|
832
694
|
if (!['Object', 'Array'].includes(type$1)) {
|
|
833
695
|
const prevSize = this.set.size;
|
|
834
696
|
this.set.add(item);
|
|
835
697
|
return this.set.size !== prevSize;
|
|
836
698
|
}
|
|
837
|
-
|
|
838
699
|
if (!(type$1 in this.items)) {
|
|
839
700
|
this.items[type$1] = [item];
|
|
840
701
|
return true;
|
|
841
702
|
}
|
|
842
|
-
|
|
843
703
|
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
844
704
|
this.items[type$1].push(item);
|
|
845
705
|
return true;
|
|
846
706
|
}
|
|
847
|
-
|
|
848
707
|
return false;
|
|
849
708
|
}
|
|
850
|
-
|
|
851
709
|
}
|
|
852
710
|
|
|
853
711
|
function uniq(list) {
|
|
@@ -870,11 +728,9 @@ function dissoc(prop, obj) {
|
|
|
870
728
|
if (arguments.length === 1) return _obj => dissoc(prop, _obj);
|
|
871
729
|
if (obj === null || obj === undefined) return {};
|
|
872
730
|
const willReturn = {};
|
|
873
|
-
|
|
874
731
|
for (const p in obj) {
|
|
875
732
|
willReturn[p] = obj[p];
|
|
876
733
|
}
|
|
877
|
-
|
|
878
734
|
delete willReturn[prop];
|
|
879
735
|
return willReturn;
|
|
880
736
|
}
|
|
@@ -893,7 +749,6 @@ function dropLast(howManyToDrop, listOrString) {
|
|
|
893
749
|
if (arguments.length === 1) {
|
|
894
750
|
return _listOrString => dropLast(howManyToDrop, _listOrString);
|
|
895
751
|
}
|
|
896
|
-
|
|
897
752
|
return howManyToDrop > 0 ? listOrString.slice(0, -howManyToDrop) : listOrString.slice();
|
|
898
753
|
}
|
|
899
754
|
|
|
@@ -901,26 +756,19 @@ function dropLastWhile(predicate, iterable) {
|
|
|
901
756
|
if (arguments.length === 1) {
|
|
902
757
|
return _iterable => dropLastWhile(predicate, _iterable);
|
|
903
758
|
}
|
|
904
|
-
|
|
905
759
|
if (iterable.length === 0) return iterable;
|
|
906
|
-
|
|
907
|
-
const isArray = _isArray(iterable);
|
|
908
|
-
|
|
760
|
+
const isArray$1 = isArray(iterable);
|
|
909
761
|
if (typeof predicate !== 'function') {
|
|
910
762
|
throw new Error(`'predicate' is from wrong type ${typeof predicate}`);
|
|
911
763
|
}
|
|
912
|
-
|
|
913
|
-
if (!isArray && typeof iterable !== 'string') {
|
|
764
|
+
if (!isArray$1 && typeof iterable !== 'string') {
|
|
914
765
|
throw new Error(`'iterable' is from wrong type ${typeof iterable}`);
|
|
915
766
|
}
|
|
916
|
-
|
|
917
767
|
let found = false;
|
|
918
768
|
const toReturn = [];
|
|
919
769
|
let counter = iterable.length;
|
|
920
|
-
|
|
921
770
|
while (counter > 0) {
|
|
922
771
|
counter--;
|
|
923
|
-
|
|
924
772
|
if (!found && predicate(iterable[counter]) === false) {
|
|
925
773
|
found = true;
|
|
926
774
|
toReturn.push(iterable[counter]);
|
|
@@ -928,21 +776,18 @@ function dropLastWhile(predicate, iterable) {
|
|
|
928
776
|
toReturn.push(iterable[counter]);
|
|
929
777
|
}
|
|
930
778
|
}
|
|
931
|
-
|
|
932
|
-
return isArray ? toReturn.reverse() : toReturn.reverse().join('');
|
|
779
|
+
return isArray$1 ? toReturn.reverse() : toReturn.reverse().join('');
|
|
933
780
|
}
|
|
934
781
|
|
|
935
782
|
function dropRepeats(list) {
|
|
936
|
-
if (!
|
|
783
|
+
if (!isArray(list)) {
|
|
937
784
|
throw new Error(`${list} is not a list`);
|
|
938
785
|
}
|
|
939
|
-
|
|
940
786
|
const toReturn = [];
|
|
941
787
|
list.reduce((prev, current) => {
|
|
942
788
|
if (!equals(prev, current)) {
|
|
943
789
|
toReturn.push(current);
|
|
944
790
|
}
|
|
945
|
-
|
|
946
791
|
return current;
|
|
947
792
|
}, undefined);
|
|
948
793
|
return toReturn;
|
|
@@ -952,22 +797,18 @@ function dropRepeatsWith(predicate, list) {
|
|
|
952
797
|
if (arguments.length === 1) {
|
|
953
798
|
return _iterable => dropRepeatsWith(predicate, _iterable);
|
|
954
799
|
}
|
|
955
|
-
|
|
956
|
-
if (!_isArray(list)) {
|
|
800
|
+
if (!isArray(list)) {
|
|
957
801
|
throw new Error(`${list} is not a list`);
|
|
958
802
|
}
|
|
959
|
-
|
|
960
803
|
const toReturn = [];
|
|
961
804
|
list.reduce((prev, current) => {
|
|
962
805
|
if (prev === undefined) {
|
|
963
806
|
toReturn.push(current);
|
|
964
807
|
return current;
|
|
965
808
|
}
|
|
966
|
-
|
|
967
809
|
if (!predicate(prev, current)) {
|
|
968
810
|
toReturn.push(current);
|
|
969
811
|
}
|
|
970
|
-
|
|
971
812
|
return current;
|
|
972
813
|
}, undefined);
|
|
973
814
|
return toReturn;
|
|
@@ -977,17 +818,13 @@ function dropWhile(predicate, iterable) {
|
|
|
977
818
|
if (arguments.length === 1) {
|
|
978
819
|
return _iterable => dropWhile(predicate, _iterable);
|
|
979
820
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
if (!isArray && typeof iterable !== 'string') {
|
|
821
|
+
const isArray$1 = isArray(iterable);
|
|
822
|
+
if (!isArray$1 && typeof iterable !== 'string') {
|
|
984
823
|
throw new Error('`iterable` is neither list nor a string');
|
|
985
824
|
}
|
|
986
|
-
|
|
987
825
|
let flag = false;
|
|
988
826
|
const holder = [];
|
|
989
827
|
let counter = -1;
|
|
990
|
-
|
|
991
828
|
while (counter++ < iterable.length - 1) {
|
|
992
829
|
if (flag) {
|
|
993
830
|
holder.push(iterable[counter]);
|
|
@@ -996,26 +833,22 @@ function dropWhile(predicate, iterable) {
|
|
|
996
833
|
holder.push(iterable[counter]);
|
|
997
834
|
}
|
|
998
835
|
}
|
|
999
|
-
|
|
1000
|
-
return isArray ? holder : holder.join('');
|
|
836
|
+
return isArray$1 ? holder : holder.join('');
|
|
1001
837
|
}
|
|
1002
838
|
|
|
1003
839
|
function either(firstPredicate, secondPredicate) {
|
|
1004
840
|
if (arguments.length === 1) {
|
|
1005
841
|
return _secondPredicate => either(firstPredicate, _secondPredicate);
|
|
1006
842
|
}
|
|
1007
|
-
|
|
1008
843
|
return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
|
1009
844
|
}
|
|
1010
845
|
|
|
1011
846
|
function endsWith(target, iterable) {
|
|
1012
847
|
if (arguments.length === 1) return _iterable => endsWith(target, _iterable);
|
|
1013
|
-
|
|
1014
848
|
if (typeof iterable === 'string') {
|
|
1015
849
|
return iterable.endsWith(target);
|
|
1016
850
|
}
|
|
1017
|
-
|
|
1018
|
-
if (!_isArray(target)) return false;
|
|
851
|
+
if (!isArray(target)) return false;
|
|
1019
852
|
const diff = iterable.length - target.length;
|
|
1020
853
|
let correct = true;
|
|
1021
854
|
const filtered = target.filter((x, index) => {
|
|
@@ -1036,7 +869,6 @@ function prop(propToFind, obj) {
|
|
|
1036
869
|
function eqPropsFn(property, objA, objB) {
|
|
1037
870
|
return equals(prop(property, objA), prop(property, objB));
|
|
1038
871
|
}
|
|
1039
|
-
|
|
1040
872
|
const eqProps = curry(eqPropsFn);
|
|
1041
873
|
|
|
1042
874
|
function evolveArray(rules, list) {
|
|
@@ -1044,7 +876,6 @@ function evolveArray(rules, list) {
|
|
|
1044
876
|
if (type(rules[i]) === 'Function') {
|
|
1045
877
|
return rules[i](x);
|
|
1046
878
|
}
|
|
1047
|
-
|
|
1048
879
|
return x;
|
|
1049
880
|
}, list, true);
|
|
1050
881
|
}
|
|
@@ -1052,22 +883,17 @@ function evolveObject(rules, iterable) {
|
|
|
1052
883
|
return mapObject((x, prop) => {
|
|
1053
884
|
if (type(x) === 'Object') {
|
|
1054
885
|
const typeRule = type(rules[prop]);
|
|
1055
|
-
|
|
1056
886
|
if (typeRule === 'Function') {
|
|
1057
887
|
return rules[prop](x);
|
|
1058
888
|
}
|
|
1059
|
-
|
|
1060
889
|
if (typeRule === 'Object') {
|
|
1061
890
|
return evolve(rules[prop], x);
|
|
1062
891
|
}
|
|
1063
|
-
|
|
1064
892
|
return x;
|
|
1065
893
|
}
|
|
1066
|
-
|
|
1067
894
|
if (type(rules[prop]) === 'Function') {
|
|
1068
895
|
return rules[prop](x);
|
|
1069
896
|
}
|
|
1070
|
-
|
|
1071
897
|
return x;
|
|
1072
898
|
}, iterable);
|
|
1073
899
|
}
|
|
@@ -1075,61 +901,48 @@ function evolve(rules, iterable) {
|
|
|
1075
901
|
if (arguments.length === 1) {
|
|
1076
902
|
return _iterable => evolve(rules, _iterable);
|
|
1077
903
|
}
|
|
1078
|
-
|
|
1079
904
|
const rulesType = type(rules);
|
|
1080
905
|
const iterableType = type(iterable);
|
|
1081
|
-
|
|
1082
906
|
if (iterableType !== rulesType) {
|
|
1083
907
|
throw new Error('iterableType !== rulesType');
|
|
1084
908
|
}
|
|
1085
|
-
|
|
1086
909
|
if (!['Object', 'Array'].includes(rulesType)) {
|
|
1087
910
|
throw new Error(`'iterable' and 'rules' are from wrong type ${rulesType}`);
|
|
1088
911
|
}
|
|
1089
|
-
|
|
1090
912
|
if (iterableType === 'Object') {
|
|
1091
913
|
return evolveObject(rules, iterable);
|
|
1092
914
|
}
|
|
1093
|
-
|
|
1094
915
|
return evolveArray(rules, iterable);
|
|
1095
916
|
}
|
|
1096
917
|
|
|
1097
918
|
function filterObject(predicate, obj) {
|
|
1098
919
|
const willReturn = {};
|
|
1099
|
-
|
|
1100
920
|
for (const prop in obj) {
|
|
1101
921
|
if (predicate(obj[prop], prop, obj)) {
|
|
1102
922
|
willReturn[prop] = obj[prop];
|
|
1103
923
|
}
|
|
1104
924
|
}
|
|
1105
|
-
|
|
1106
925
|
return willReturn;
|
|
1107
926
|
}
|
|
1108
927
|
function filterArray(predicate, list, indexed = false) {
|
|
1109
928
|
let index = 0;
|
|
1110
929
|
const len = list.length;
|
|
1111
930
|
const willReturn = [];
|
|
1112
|
-
|
|
1113
931
|
while (index < len) {
|
|
1114
932
|
const predicateResult = indexed ? predicate(list[index], index) : predicate(list[index]);
|
|
1115
|
-
|
|
1116
933
|
if (predicateResult) {
|
|
1117
934
|
willReturn.push(list[index]);
|
|
1118
935
|
}
|
|
1119
|
-
|
|
1120
936
|
index++;
|
|
1121
937
|
}
|
|
1122
|
-
|
|
1123
938
|
return willReturn;
|
|
1124
939
|
}
|
|
1125
940
|
function filter(predicate, iterable) {
|
|
1126
941
|
if (arguments.length === 1) return _iterable => filter(predicate, _iterable);
|
|
1127
|
-
|
|
1128
942
|
if (!iterable) {
|
|
1129
943
|
throw new Error('Incorrect iterable input');
|
|
1130
944
|
}
|
|
1131
|
-
|
|
1132
|
-
if (_isArray(iterable)) return filterArray(predicate, iterable, false);
|
|
945
|
+
if (isArray(iterable)) return filterArray(predicate, iterable, false);
|
|
1133
946
|
return filterObject(predicate, iterable);
|
|
1134
947
|
}
|
|
1135
948
|
|
|
@@ -1137,14 +950,11 @@ function find(predicate, list) {
|
|
|
1137
950
|
if (arguments.length === 1) return _list => find(predicate, _list);
|
|
1138
951
|
let index = 0;
|
|
1139
952
|
const len = list.length;
|
|
1140
|
-
|
|
1141
953
|
while (index < len) {
|
|
1142
954
|
const x = list[index];
|
|
1143
|
-
|
|
1144
955
|
if (predicate(x)) {
|
|
1145
956
|
return x;
|
|
1146
957
|
}
|
|
1147
|
-
|
|
1148
958
|
index++;
|
|
1149
959
|
}
|
|
1150
960
|
}
|
|
@@ -1153,53 +963,45 @@ function findIndex(predicate, list) {
|
|
|
1153
963
|
if (arguments.length === 1) return _list => findIndex(predicate, _list);
|
|
1154
964
|
const len = list.length;
|
|
1155
965
|
let index = -1;
|
|
1156
|
-
|
|
1157
966
|
while (++index < len) {
|
|
1158
967
|
if (predicate(list[index])) {
|
|
1159
968
|
return index;
|
|
1160
969
|
}
|
|
1161
970
|
}
|
|
1162
|
-
|
|
1163
971
|
return -1;
|
|
1164
972
|
}
|
|
1165
973
|
|
|
1166
974
|
function findLast(predicate, list) {
|
|
1167
975
|
if (arguments.length === 1) return _list => findLast(predicate, _list);
|
|
1168
976
|
let index = list.length;
|
|
1169
|
-
|
|
1170
977
|
while (--index >= 0) {
|
|
1171
978
|
if (predicate(list[index])) {
|
|
1172
979
|
return list[index];
|
|
1173
980
|
}
|
|
1174
981
|
}
|
|
1175
|
-
|
|
1176
982
|
return undefined;
|
|
1177
983
|
}
|
|
1178
984
|
|
|
1179
985
|
function findLastIndex(fn, list) {
|
|
1180
986
|
if (arguments.length === 1) return _list => findLastIndex(fn, _list);
|
|
1181
987
|
let index = list.length;
|
|
1182
|
-
|
|
1183
988
|
while (--index >= 0) {
|
|
1184
989
|
if (fn(list[index])) {
|
|
1185
990
|
return index;
|
|
1186
991
|
}
|
|
1187
992
|
}
|
|
1188
|
-
|
|
1189
993
|
return -1;
|
|
1190
994
|
}
|
|
1191
995
|
|
|
1192
996
|
function flatten(list, input) {
|
|
1193
997
|
const willReturn = input === undefined ? [] : input;
|
|
1194
|
-
|
|
1195
998
|
for (let i = 0; i < list.length; i++) {
|
|
1196
|
-
if (
|
|
999
|
+
if (isArray(list[i])) {
|
|
1197
1000
|
flatten(list[i], willReturn);
|
|
1198
1001
|
} else {
|
|
1199
1002
|
willReturn.push(list[i]);
|
|
1200
1003
|
}
|
|
1201
1004
|
}
|
|
1202
|
-
|
|
1203
1005
|
return willReturn;
|
|
1204
1006
|
}
|
|
1205
1007
|
|
|
@@ -1214,44 +1016,35 @@ function flipFn(fn) {
|
|
|
1214
1016
|
} else if (input.length === 4) {
|
|
1215
1017
|
return fn(input[1], input[0], input[2], input[3]);
|
|
1216
1018
|
}
|
|
1217
|
-
|
|
1218
1019
|
throw new Error('R.flip doesn\'t work with arity > 4');
|
|
1219
1020
|
};
|
|
1220
1021
|
}
|
|
1221
|
-
|
|
1222
1022
|
function flip(fn) {
|
|
1223
1023
|
return flipFn(fn);
|
|
1224
1024
|
}
|
|
1225
1025
|
|
|
1226
1026
|
function forEach(fn, list) {
|
|
1227
1027
|
if (arguments.length === 1) return _list => forEach(fn, _list);
|
|
1228
|
-
|
|
1229
1028
|
if (list === undefined) {
|
|
1230
1029
|
return;
|
|
1231
1030
|
}
|
|
1232
|
-
|
|
1233
|
-
if (_isArray(list)) {
|
|
1031
|
+
if (isArray(list)) {
|
|
1234
1032
|
let index = 0;
|
|
1235
1033
|
const len = list.length;
|
|
1236
|
-
|
|
1237
1034
|
while (index < len) {
|
|
1238
1035
|
fn(list[index]);
|
|
1239
1036
|
index++;
|
|
1240
1037
|
}
|
|
1241
1038
|
} else {
|
|
1242
1039
|
let index = 0;
|
|
1243
|
-
|
|
1244
|
-
const
|
|
1245
|
-
|
|
1246
|
-
const len = keys.length;
|
|
1247
|
-
|
|
1040
|
+
const listKeys = keys$1(list);
|
|
1041
|
+
const len = listKeys.length;
|
|
1248
1042
|
while (index < len) {
|
|
1249
|
-
const key =
|
|
1043
|
+
const key = listKeys[index];
|
|
1250
1044
|
fn(list[key], key, list);
|
|
1251
1045
|
index++;
|
|
1252
1046
|
}
|
|
1253
1047
|
}
|
|
1254
|
-
|
|
1255
1048
|
return list;
|
|
1256
1049
|
}
|
|
1257
1050
|
|
|
@@ -1264,23 +1057,19 @@ function fromPairs(listOfPairs) {
|
|
|
1264
1057
|
function groupBy(groupFn, list) {
|
|
1265
1058
|
if (arguments.length === 1) return _list => groupBy(groupFn, _list);
|
|
1266
1059
|
const result = {};
|
|
1267
|
-
|
|
1268
1060
|
for (let i = 0; i < list.length; i++) {
|
|
1269
1061
|
const item = list[i];
|
|
1270
1062
|
const key = groupFn(item);
|
|
1271
|
-
|
|
1272
1063
|
if (!result[key]) {
|
|
1273
1064
|
result[key] = [];
|
|
1274
1065
|
}
|
|
1275
|
-
|
|
1276
1066
|
result[key].push(item);
|
|
1277
1067
|
}
|
|
1278
|
-
|
|
1279
1068
|
return result;
|
|
1280
1069
|
}
|
|
1281
1070
|
|
|
1282
1071
|
function groupWith(compareFn, list) {
|
|
1283
|
-
if (!
|
|
1072
|
+
if (!isArray(list)) throw new TypeError('list.reduce is not a function');
|
|
1284
1073
|
const clone = cloneList(list);
|
|
1285
1074
|
if (list.length === 1) return [clone];
|
|
1286
1075
|
const toReturn = [];
|
|
@@ -1290,20 +1079,17 @@ function groupWith(compareFn, list) {
|
|
|
1290
1079
|
const okCompare = compareFn(prev, current);
|
|
1291
1080
|
const holderIsEmpty = holder.length === 0;
|
|
1292
1081
|
const lastCall = i === list.length - 1;
|
|
1293
|
-
|
|
1294
1082
|
if (okCompare) {
|
|
1295
1083
|
if (holderIsEmpty) holder.push(prev);
|
|
1296
1084
|
holder.push(current);
|
|
1297
1085
|
if (lastCall) toReturn.push(holder);
|
|
1298
1086
|
return current;
|
|
1299
1087
|
}
|
|
1300
|
-
|
|
1301
1088
|
if (holderIsEmpty) {
|
|
1302
1089
|
toReturn.push([prev]);
|
|
1303
1090
|
if (lastCall) toReturn.push([current]);
|
|
1304
1091
|
return current;
|
|
1305
1092
|
}
|
|
1306
|
-
|
|
1307
1093
|
toReturn.push(holder);
|
|
1308
1094
|
if (lastCall) toReturn.push([current]);
|
|
1309
1095
|
holder = [];
|
|
@@ -1324,25 +1110,20 @@ function createPath(path, delimiter = '.') {
|
|
|
1324
1110
|
|
|
1325
1111
|
function path(pathInput, obj) {
|
|
1326
1112
|
if (arguments.length === 1) return _obj => path(pathInput, _obj);
|
|
1327
|
-
|
|
1328
1113
|
if (obj === null || obj === undefined) {
|
|
1329
1114
|
return undefined;
|
|
1330
1115
|
}
|
|
1331
|
-
|
|
1332
1116
|
let willReturn = obj;
|
|
1333
1117
|
let counter = 0;
|
|
1334
1118
|
const pathArrValue = createPath(pathInput);
|
|
1335
|
-
|
|
1336
1119
|
while (counter < pathArrValue.length) {
|
|
1337
1120
|
if (willReturn === null || willReturn === undefined) {
|
|
1338
1121
|
return undefined;
|
|
1339
1122
|
}
|
|
1340
|
-
|
|
1341
1123
|
if (willReturn[pathArrValue[counter]] === null) return undefined;
|
|
1342
1124
|
willReturn = willReturn[pathArrValue[counter]];
|
|
1343
1125
|
counter++;
|
|
1344
1126
|
}
|
|
1345
|
-
|
|
1346
1127
|
return willReturn;
|
|
1347
1128
|
}
|
|
1348
1129
|
|
|
@@ -1350,7 +1131,6 @@ function hasPath(pathInput, obj) {
|
|
|
1350
1131
|
if (arguments.length === 1) {
|
|
1351
1132
|
return objHolder => hasPath(pathInput, objHolder);
|
|
1352
1133
|
}
|
|
1353
|
-
|
|
1354
1134
|
return path(pathInput, obj) !== undefined;
|
|
1355
1135
|
}
|
|
1356
1136
|
|
|
@@ -1363,14 +1143,13 @@ function _objectIs(a, b) {
|
|
|
1363
1143
|
if (a === b) {
|
|
1364
1144
|
return a !== 0 || 1 / a === 1 / b;
|
|
1365
1145
|
}
|
|
1366
|
-
|
|
1367
1146
|
return a !== a && b !== b;
|
|
1368
1147
|
}
|
|
1369
|
-
|
|
1148
|
+
const objectIs = Object.is || _objectIs;
|
|
1370
1149
|
|
|
1371
1150
|
function identical(a, b) {
|
|
1372
1151
|
if (arguments.length === 1) return _b => identical(a, _b);
|
|
1373
|
-
return
|
|
1152
|
+
return objectIs(a, b);
|
|
1374
1153
|
}
|
|
1375
1154
|
|
|
1376
1155
|
function identity(x) {
|
|
@@ -1380,46 +1159,36 @@ function identity(x) {
|
|
|
1380
1159
|
function ifElseFn(condition, onTrue, onFalse) {
|
|
1381
1160
|
return (...input) => {
|
|
1382
1161
|
const conditionResult = typeof condition === 'boolean' ? condition : condition(...input);
|
|
1383
|
-
|
|
1384
1162
|
if (conditionResult === true) {
|
|
1385
1163
|
return onTrue(...input);
|
|
1386
1164
|
}
|
|
1387
|
-
|
|
1388
1165
|
return onFalse(...input);
|
|
1389
1166
|
};
|
|
1390
1167
|
}
|
|
1391
|
-
|
|
1392
1168
|
const ifElse = curry(ifElseFn);
|
|
1393
1169
|
|
|
1394
1170
|
const inc = x => x + 1;
|
|
1395
1171
|
|
|
1396
1172
|
function indexByPath(pathInput, list) {
|
|
1397
1173
|
const toReturn = {};
|
|
1398
|
-
|
|
1399
1174
|
for (let i = 0; i < list.length; i++) {
|
|
1400
1175
|
const item = list[i];
|
|
1401
1176
|
toReturn[path(pathInput, item)] = item;
|
|
1402
1177
|
}
|
|
1403
|
-
|
|
1404
1178
|
return toReturn;
|
|
1405
1179
|
}
|
|
1406
|
-
|
|
1407
1180
|
function indexBy(condition, list) {
|
|
1408
1181
|
if (arguments.length === 1) {
|
|
1409
1182
|
return _list => indexBy(condition, _list);
|
|
1410
1183
|
}
|
|
1411
|
-
|
|
1412
1184
|
if (typeof condition === 'string') {
|
|
1413
1185
|
return indexByPath(condition, list);
|
|
1414
1186
|
}
|
|
1415
|
-
|
|
1416
1187
|
const toReturn = {};
|
|
1417
|
-
|
|
1418
1188
|
for (let i = 0; i < list.length; i++) {
|
|
1419
1189
|
const item = list[i];
|
|
1420
1190
|
toReturn[condition(item)] = item;
|
|
1421
1191
|
}
|
|
1422
|
-
|
|
1423
1192
|
return toReturn;
|
|
1424
1193
|
}
|
|
1425
1194
|
|
|
@@ -1427,7 +1196,6 @@ function indexOf(valueToFind, list) {
|
|
|
1427
1196
|
if (arguments.length === 1) {
|
|
1428
1197
|
return _list => _indexOf(valueToFind, _list);
|
|
1429
1198
|
}
|
|
1430
|
-
|
|
1431
1199
|
return _indexOf(valueToFind, list);
|
|
1432
1200
|
}
|
|
1433
1201
|
|
|
@@ -1437,19 +1205,15 @@ function baseSlice(array, start, end) {
|
|
|
1437
1205
|
length
|
|
1438
1206
|
} = array;
|
|
1439
1207
|
end = end > length ? length : end;
|
|
1440
|
-
|
|
1441
1208
|
if (end < 0) {
|
|
1442
1209
|
end += length;
|
|
1443
1210
|
}
|
|
1444
|
-
|
|
1445
1211
|
length = start > end ? 0 : end - start >>> 0;
|
|
1446
1212
|
start >>>= 0;
|
|
1447
1213
|
const result = Array(length);
|
|
1448
|
-
|
|
1449
1214
|
while (++index < length) {
|
|
1450
1215
|
result[index] = array[index + start];
|
|
1451
1216
|
}
|
|
1452
|
-
|
|
1453
1217
|
return result;
|
|
1454
1218
|
}
|
|
1455
1219
|
|
|
@@ -1468,7 +1232,6 @@ function intersperse(separator, list) {
|
|
|
1468
1232
|
let index = -1;
|
|
1469
1233
|
const len = list.length;
|
|
1470
1234
|
const willReturn = [];
|
|
1471
|
-
|
|
1472
1235
|
while (++index < len) {
|
|
1473
1236
|
if (index === len - 1) {
|
|
1474
1237
|
willReturn.push(list[index]);
|
|
@@ -1476,7 +1239,6 @@ function intersperse(separator, list) {
|
|
|
1476
1239
|
willReturn.push(list[index], separator);
|
|
1477
1240
|
}
|
|
1478
1241
|
}
|
|
1479
|
-
|
|
1480
1242
|
return willReturn;
|
|
1481
1243
|
}
|
|
1482
1244
|
|
|
@@ -1489,15 +1251,12 @@ function isEmpty(input) {
|
|
|
1489
1251
|
const inputType = type(input);
|
|
1490
1252
|
if (['Undefined', 'NaN', 'Number', 'Null'].includes(inputType)) return false;
|
|
1491
1253
|
if (!input) return true;
|
|
1492
|
-
|
|
1493
1254
|
if (inputType === 'Object') {
|
|
1494
1255
|
return Object.keys(input).length === 0;
|
|
1495
1256
|
}
|
|
1496
|
-
|
|
1497
1257
|
if (inputType === 'Array') {
|
|
1498
1258
|
return input.length === 0;
|
|
1499
1259
|
}
|
|
1500
|
-
|
|
1501
1260
|
return false;
|
|
1502
1261
|
}
|
|
1503
1262
|
|
|
@@ -1522,7 +1281,6 @@ function last(listOrString) {
|
|
|
1522
1281
|
if (typeof listOrString === 'string') {
|
|
1523
1282
|
return listOrString[listOrString.length - 1] || '';
|
|
1524
1283
|
}
|
|
1525
|
-
|
|
1526
1284
|
return listOrString[listOrString.length - 1];
|
|
1527
1285
|
}
|
|
1528
1286
|
|
|
@@ -1530,12 +1288,11 @@ function lastIndexOf(valueToFind, list) {
|
|
|
1530
1288
|
if (arguments.length === 1) {
|
|
1531
1289
|
return _list => _lastIndexOf(valueToFind, _list);
|
|
1532
1290
|
}
|
|
1533
|
-
|
|
1534
1291
|
return _lastIndexOf(valueToFind, list);
|
|
1535
1292
|
}
|
|
1536
1293
|
|
|
1537
1294
|
function length(x) {
|
|
1538
|
-
if (
|
|
1295
|
+
if (isArray(x)) return x.length;
|
|
1539
1296
|
if (typeof x === 'string') return x.length;
|
|
1540
1297
|
return NaN;
|
|
1541
1298
|
}
|
|
@@ -1559,7 +1316,6 @@ function updateFn(index, newValue, list) {
|
|
|
1559
1316
|
if (index === -1) return clone.fill(newValue, index);
|
|
1560
1317
|
return clone.fill(newValue, index, index + 1);
|
|
1561
1318
|
}
|
|
1562
|
-
|
|
1563
1319
|
const update = curry(updateFn);
|
|
1564
1320
|
|
|
1565
1321
|
function lensIndex(index) {
|
|
@@ -1582,7 +1338,7 @@ function match(pattern, input) {
|
|
|
1582
1338
|
|
|
1583
1339
|
function mathMod(x, y) {
|
|
1584
1340
|
if (arguments.length === 1) return _y => mathMod(x, _y);
|
|
1585
|
-
if (!
|
|
1341
|
+
if (!isInteger(x) || !isInteger(y) || y < 1) return NaN;
|
|
1586
1342
|
return (x % y + y) % y;
|
|
1587
1343
|
}
|
|
1588
1344
|
|
|
@@ -1627,8 +1383,7 @@ function mergeDeepRight(target, source) {
|
|
|
1627
1383
|
if (arguments.length === 1) {
|
|
1628
1384
|
return sourceHolder => mergeDeepRight(target, sourceHolder);
|
|
1629
1385
|
}
|
|
1630
|
-
|
|
1631
|
-
const willReturn = JSON.parse(JSON.stringify(target));
|
|
1386
|
+
const willReturn = clone(target);
|
|
1632
1387
|
Object.keys(source).forEach(key => {
|
|
1633
1388
|
if (type(source[key]) === 'Object') {
|
|
1634
1389
|
if (type(target[key]) === 'Object') {
|
|
@@ -1659,7 +1414,6 @@ function mergeWithFn(mergeFn, a, b) {
|
|
|
1659
1414
|
});
|
|
1660
1415
|
Object.keys(b).forEach(key => {
|
|
1661
1416
|
if (willReturn[key] !== undefined) return;
|
|
1662
|
-
|
|
1663
1417
|
if (a[key] === undefined) {
|
|
1664
1418
|
willReturn[key] = b[key];
|
|
1665
1419
|
} else {
|
|
@@ -1668,7 +1422,6 @@ function mergeWithFn(mergeFn, a, b) {
|
|
|
1668
1422
|
});
|
|
1669
1423
|
return willReturn;
|
|
1670
1424
|
}
|
|
1671
|
-
|
|
1672
1425
|
const mergeWith = curry(mergeWithFn);
|
|
1673
1426
|
|
|
1674
1427
|
function min(x, y) {
|
|
@@ -1683,17 +1436,14 @@ const minBy = curry(minByFn);
|
|
|
1683
1436
|
|
|
1684
1437
|
function ownKeys(object, enumerableOnly) {
|
|
1685
1438
|
var keys = Object.keys(object);
|
|
1686
|
-
|
|
1687
1439
|
if (Object.getOwnPropertySymbols) {
|
|
1688
1440
|
var symbols = Object.getOwnPropertySymbols(object);
|
|
1689
1441
|
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
1690
1442
|
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
1691
1443
|
})), keys.push.apply(keys, symbols);
|
|
1692
1444
|
}
|
|
1693
|
-
|
|
1694
1445
|
return keys;
|
|
1695
1446
|
}
|
|
1696
|
-
|
|
1697
1447
|
function _objectSpread2(target) {
|
|
1698
1448
|
for (var i = 1; i < arguments.length; i++) {
|
|
1699
1449
|
var source = null != arguments[i] ? arguments[i] : {};
|
|
@@ -1703,10 +1453,8 @@ function _objectSpread2(target) {
|
|
|
1703
1453
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
1704
1454
|
});
|
|
1705
1455
|
}
|
|
1706
|
-
|
|
1707
1456
|
return target;
|
|
1708
1457
|
}
|
|
1709
|
-
|
|
1710
1458
|
function _defineProperty(obj, key, value) {
|
|
1711
1459
|
if (key in obj) {
|
|
1712
1460
|
Object.defineProperty(obj, key, {
|
|
@@ -1718,26 +1466,37 @@ function _defineProperty(obj, key, value) {
|
|
|
1718
1466
|
} else {
|
|
1719
1467
|
obj[key] = value;
|
|
1720
1468
|
}
|
|
1721
|
-
|
|
1722
1469
|
return obj;
|
|
1723
1470
|
}
|
|
1724
1471
|
|
|
1472
|
+
function isIterable(input) {
|
|
1473
|
+
return Array.isArray(input) || type(input) === 'Object';
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
function modifyFn(property, fn, iterable) {
|
|
1477
|
+
if (!isIterable(iterable)) return iterable;
|
|
1478
|
+
if (iterable[property] === undefined) return iterable;
|
|
1479
|
+
if (isArray(iterable)) {
|
|
1480
|
+
return updateFn(property, fn(iterable[property]), iterable);
|
|
1481
|
+
}
|
|
1482
|
+
return _objectSpread2(_objectSpread2({}, iterable), {}, {
|
|
1483
|
+
[property]: fn(iterable[property])
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
const modify = curry(modifyFn);
|
|
1487
|
+
|
|
1725
1488
|
function modifyPathFn(pathInput, fn, object) {
|
|
1726
1489
|
const path$1 = createPath(pathInput);
|
|
1727
|
-
|
|
1728
1490
|
if (path$1.length === 1) {
|
|
1729
1491
|
return _objectSpread2(_objectSpread2({}, object), {}, {
|
|
1730
1492
|
[path$1[0]]: fn(object[path$1[0]])
|
|
1731
1493
|
});
|
|
1732
1494
|
}
|
|
1733
|
-
|
|
1734
1495
|
if (path(path$1, object) === undefined) return object;
|
|
1735
1496
|
const val = modifyPath(Array.prototype.slice.call(path$1, 1), fn, object[path$1[0]]);
|
|
1736
|
-
|
|
1737
1497
|
if (val === object[path$1[0]]) {
|
|
1738
1498
|
return object;
|
|
1739
1499
|
}
|
|
1740
|
-
|
|
1741
1500
|
return assoc(path$1[0], val, object);
|
|
1742
1501
|
}
|
|
1743
1502
|
const modifyPath = curry(modifyPathFn);
|
|
@@ -1751,14 +1510,12 @@ function moveFn(fromIndex, toIndex, list) {
|
|
|
1751
1510
|
if (fromIndex < 0 || toIndex < 0) {
|
|
1752
1511
|
throw new Error('Rambda.move does not support negative indexes');
|
|
1753
1512
|
}
|
|
1754
|
-
|
|
1755
1513
|
if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
|
1756
1514
|
const clone = cloneList(list);
|
|
1757
1515
|
clone[fromIndex] = list[toIndex];
|
|
1758
1516
|
clone[toIndex] = list[fromIndex];
|
|
1759
1517
|
return clone;
|
|
1760
1518
|
}
|
|
1761
|
-
|
|
1762
1519
|
const move = curry(moveFn);
|
|
1763
1520
|
|
|
1764
1521
|
function multiply(x, y) {
|
|
@@ -1772,14 +1529,14 @@ function negate(x) {
|
|
|
1772
1529
|
|
|
1773
1530
|
function none(predicate, list) {
|
|
1774
1531
|
if (arguments.length === 1) return _list => none(predicate, _list);
|
|
1775
|
-
|
|
1776
1532
|
for (let i = 0; i < list.length; i++) {
|
|
1777
1533
|
if (predicate(list[i])) return false;
|
|
1778
1534
|
}
|
|
1779
|
-
|
|
1780
1535
|
return true;
|
|
1781
1536
|
}
|
|
1782
1537
|
|
|
1538
|
+
function nop() {}
|
|
1539
|
+
|
|
1783
1540
|
function not(input) {
|
|
1784
1541
|
return !input;
|
|
1785
1542
|
}
|
|
@@ -1788,7 +1545,6 @@ function objOf(key, value) {
|
|
|
1788
1545
|
if (arguments.length === 1) {
|
|
1789
1546
|
return _value => objOf(key, _value);
|
|
1790
1547
|
}
|
|
1791
|
-
|
|
1792
1548
|
return {
|
|
1793
1549
|
[key]: value
|
|
1794
1550
|
};
|
|
@@ -1800,20 +1556,16 @@ function of(value) {
|
|
|
1800
1556
|
|
|
1801
1557
|
function omit(propsToOmit, obj) {
|
|
1802
1558
|
if (arguments.length === 1) return _obj => omit(propsToOmit, _obj);
|
|
1803
|
-
|
|
1804
1559
|
if (obj === null || obj === undefined) {
|
|
1805
1560
|
return undefined;
|
|
1806
1561
|
}
|
|
1807
|
-
|
|
1808
1562
|
const propsToOmitValue = createPath(propsToOmit, ',');
|
|
1809
1563
|
const willReturn = {};
|
|
1810
|
-
|
|
1811
1564
|
for (const key in obj) {
|
|
1812
1565
|
if (!propsToOmitValue.includes(key)) {
|
|
1813
1566
|
willReturn[key] = obj[key];
|
|
1814
1567
|
}
|
|
1815
1568
|
}
|
|
1816
|
-
|
|
1817
1569
|
return willReturn;
|
|
1818
1570
|
}
|
|
1819
1571
|
|
|
@@ -1821,11 +1573,9 @@ function on(binaryFn, unaryFn, a, b) {
|
|
|
1821
1573
|
if (arguments.length === 3) {
|
|
1822
1574
|
return _b => on(binaryFn, unaryFn, a, _b);
|
|
1823
1575
|
}
|
|
1824
|
-
|
|
1825
1576
|
if (arguments.length === 2) {
|
|
1826
1577
|
return (_a, _b) => on(binaryFn, unaryFn, _a, _b);
|
|
1827
1578
|
}
|
|
1828
|
-
|
|
1829
1579
|
return binaryFn(unaryFn(a), unaryFn(b));
|
|
1830
1580
|
}
|
|
1831
1581
|
|
|
@@ -1836,17 +1586,14 @@ function onceFn(fn, context) {
|
|
|
1836
1586
|
result = fn.apply(context || this, arguments);
|
|
1837
1587
|
fn = null;
|
|
1838
1588
|
}
|
|
1839
|
-
|
|
1840
1589
|
return result;
|
|
1841
1590
|
};
|
|
1842
1591
|
}
|
|
1843
|
-
|
|
1844
1592
|
function once(fn, context) {
|
|
1845
1593
|
if (arguments.length === 1) {
|
|
1846
1594
|
const wrap = onceFn(fn, context);
|
|
1847
1595
|
return curry(wrap);
|
|
1848
1596
|
}
|
|
1849
|
-
|
|
1850
1597
|
return onceFn(fn, context);
|
|
1851
1598
|
}
|
|
1852
1599
|
|
|
@@ -1859,11 +1606,9 @@ const Identity = x => ({
|
|
|
1859
1606
|
x,
|
|
1860
1607
|
map: fn => Identity(fn(x))
|
|
1861
1608
|
});
|
|
1862
|
-
|
|
1863
1609
|
function overFn(lens, fn, object) {
|
|
1864
1610
|
return lens(x => Identity(fn(x)))(object).x;
|
|
1865
1611
|
}
|
|
1866
|
-
|
|
1867
1612
|
const over = curry(overFn);
|
|
1868
1613
|
|
|
1869
1614
|
function partial(fn, ...args) {
|
|
@@ -1872,21 +1617,12 @@ function partial(fn, ...args) {
|
|
|
1872
1617
|
if (args.length + rest.length >= len) {
|
|
1873
1618
|
return fn(...args, ...rest);
|
|
1874
1619
|
}
|
|
1875
|
-
|
|
1876
1620
|
return partial(fn, ...[...args, ...rest]);
|
|
1877
1621
|
};
|
|
1878
1622
|
}
|
|
1879
1623
|
|
|
1880
1624
|
function partialObject(fn, input) {
|
|
1881
|
-
return
|
|
1882
|
-
if (type(fn) === 'Async') {
|
|
1883
|
-
return new Promise((resolve, reject) => {
|
|
1884
|
-
fn(mergeDeepRight(rest, input)).then(resolve).catch(reject);
|
|
1885
|
-
});
|
|
1886
|
-
}
|
|
1887
|
-
|
|
1888
|
-
return fn(mergeDeepRight(rest, input));
|
|
1889
|
-
};
|
|
1625
|
+
return nextInput => fn(mergeDeepRight(nextInput, input));
|
|
1890
1626
|
}
|
|
1891
1627
|
|
|
1892
1628
|
function partitionObject(predicate, iterable) {
|
|
@@ -1905,7 +1641,6 @@ function partitionArray(predicate, list, indexed = false) {
|
|
|
1905
1641
|
const yes = [];
|
|
1906
1642
|
const no = [];
|
|
1907
1643
|
let counter = -1;
|
|
1908
|
-
|
|
1909
1644
|
while (counter++ < list.length - 1) {
|
|
1910
1645
|
if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
|
|
1911
1646
|
yes.push(list[counter]);
|
|
@@ -1913,81 +1648,66 @@ function partitionArray(predicate, list, indexed = false) {
|
|
|
1913
1648
|
no.push(list[counter]);
|
|
1914
1649
|
}
|
|
1915
1650
|
}
|
|
1916
|
-
|
|
1917
1651
|
return [yes, no];
|
|
1918
1652
|
}
|
|
1919
1653
|
function partition(predicate, iterable) {
|
|
1920
1654
|
if (arguments.length === 1) {
|
|
1921
1655
|
return listHolder => partition(predicate, listHolder);
|
|
1922
1656
|
}
|
|
1923
|
-
|
|
1924
|
-
if (!_isArray(iterable)) return partitionObject(predicate, iterable);
|
|
1657
|
+
if (!isArray(iterable)) return partitionObject(predicate, iterable);
|
|
1925
1658
|
return partitionArray(predicate, iterable);
|
|
1926
1659
|
}
|
|
1927
1660
|
|
|
1928
1661
|
function pathEqFn(pathToSearch, target, input) {
|
|
1929
1662
|
return equals(path(pathToSearch, input), target);
|
|
1930
1663
|
}
|
|
1931
|
-
|
|
1932
1664
|
const pathEq = curry(pathEqFn);
|
|
1933
1665
|
|
|
1934
1666
|
function pathOrFn(defaultValue, pathInput, obj) {
|
|
1935
1667
|
return defaultTo(defaultValue, path(pathInput, obj));
|
|
1936
1668
|
}
|
|
1937
|
-
|
|
1938
1669
|
const pathOr = curry(pathOrFn);
|
|
1939
1670
|
|
|
1940
1671
|
function paths(pathsToSearch, obj) {
|
|
1941
1672
|
if (arguments.length === 1) {
|
|
1942
1673
|
return _obj => paths(pathsToSearch, _obj);
|
|
1943
1674
|
}
|
|
1944
|
-
|
|
1945
1675
|
return pathsToSearch.map(singlePath => path(singlePath, obj));
|
|
1946
1676
|
}
|
|
1947
1677
|
|
|
1948
1678
|
function pick(propsToPick, input) {
|
|
1949
1679
|
if (arguments.length === 1) return _input => pick(propsToPick, _input);
|
|
1950
|
-
|
|
1951
1680
|
if (input === null || input === undefined) {
|
|
1952
1681
|
return undefined;
|
|
1953
1682
|
}
|
|
1954
|
-
|
|
1955
1683
|
const keys = createPath(propsToPick, ',');
|
|
1956
1684
|
const willReturn = {};
|
|
1957
1685
|
let counter = 0;
|
|
1958
|
-
|
|
1959
1686
|
while (counter < keys.length) {
|
|
1960
1687
|
if (keys[counter] in input) {
|
|
1961
1688
|
willReturn[keys[counter]] = input[keys[counter]];
|
|
1962
1689
|
}
|
|
1963
|
-
|
|
1964
1690
|
counter++;
|
|
1965
1691
|
}
|
|
1966
|
-
|
|
1967
1692
|
return willReturn;
|
|
1968
1693
|
}
|
|
1969
1694
|
|
|
1970
1695
|
function pickAll(propsToPick, obj) {
|
|
1971
1696
|
if (arguments.length === 1) return _obj => pickAll(propsToPick, _obj);
|
|
1972
|
-
|
|
1973
1697
|
if (obj === null || obj === undefined) {
|
|
1974
1698
|
return undefined;
|
|
1975
1699
|
}
|
|
1976
|
-
|
|
1977
1700
|
const keysValue = createPath(propsToPick, ',');
|
|
1978
1701
|
const willReturn = {};
|
|
1979
1702
|
let counter = 0;
|
|
1980
|
-
|
|
1981
1703
|
while (counter < keysValue.length) {
|
|
1982
1704
|
if (keysValue[counter] in obj) {
|
|
1983
1705
|
willReturn[keysValue[counter]] = obj[keysValue[counter]];
|
|
1984
1706
|
} else {
|
|
1985
1707
|
willReturn[keysValue[counter]] = undefined;
|
|
1986
1708
|
}
|
|
1987
|
-
|
|
1988
1709
|
counter++;
|
|
1989
1710
|
}
|
|
1990
|
-
|
|
1991
1711
|
return willReturn;
|
|
1992
1712
|
}
|
|
1993
1713
|
|
|
@@ -2014,55 +1734,45 @@ function propEqFn(propToFind, valueToMatch, obj) {
|
|
|
2014
1734
|
if (!obj) return false;
|
|
2015
1735
|
return equals(valueToMatch, prop(propToFind, obj));
|
|
2016
1736
|
}
|
|
2017
|
-
|
|
2018
1737
|
const propEq = curry(propEqFn);
|
|
2019
1738
|
|
|
2020
1739
|
function propIsFn(targetPrototype, property, obj) {
|
|
2021
1740
|
return is(targetPrototype, obj[property]);
|
|
2022
1741
|
}
|
|
2023
|
-
|
|
2024
1742
|
const propIs = curry(propIsFn);
|
|
2025
1743
|
|
|
2026
1744
|
function propOrFn(defaultValue, property, obj) {
|
|
2027
1745
|
if (!obj) return defaultValue;
|
|
2028
1746
|
return defaultTo(defaultValue, obj[property]);
|
|
2029
1747
|
}
|
|
2030
|
-
|
|
2031
1748
|
const propOr = curry(propOrFn);
|
|
2032
1749
|
|
|
2033
1750
|
function propSatisfiesFn(predicate, property, obj) {
|
|
2034
1751
|
return predicate(prop(property, obj));
|
|
2035
1752
|
}
|
|
2036
|
-
|
|
2037
1753
|
const propSatisfies = curry(propSatisfiesFn);
|
|
2038
1754
|
|
|
2039
1755
|
function props(propsToPick, obj) {
|
|
2040
1756
|
if (arguments.length === 1) {
|
|
2041
1757
|
return _obj => props(propsToPick, _obj);
|
|
2042
1758
|
}
|
|
2043
|
-
|
|
2044
|
-
if (!_isArray(propsToPick)) {
|
|
1759
|
+
if (!isArray(propsToPick)) {
|
|
2045
1760
|
throw new Error('propsToPick is not a list');
|
|
2046
1761
|
}
|
|
2047
|
-
|
|
2048
1762
|
return mapArray(prop => obj[prop], propsToPick);
|
|
2049
1763
|
}
|
|
2050
1764
|
|
|
2051
1765
|
function range(start, end) {
|
|
2052
1766
|
if (arguments.length === 1) return _end => range(start, _end);
|
|
2053
|
-
|
|
2054
1767
|
if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
|
|
2055
1768
|
throw new TypeError('Both arguments to range must be numbers');
|
|
2056
1769
|
}
|
|
2057
|
-
|
|
2058
1770
|
if (end < start) return [];
|
|
2059
1771
|
const len = end - start;
|
|
2060
1772
|
const willReturn = Array(len);
|
|
2061
|
-
|
|
2062
1773
|
for (let i = 0; i < len; i++) {
|
|
2063
1774
|
willReturn[i] = start + i;
|
|
2064
1775
|
}
|
|
2065
|
-
|
|
2066
1776
|
return willReturn;
|
|
2067
1777
|
}
|
|
2068
1778
|
|
|
@@ -2075,21 +1785,18 @@ function repeat(x, timesToRepeat) {
|
|
|
2075
1785
|
if (arguments.length === 1) {
|
|
2076
1786
|
return _timesToRepeat => repeat(x, _timesToRepeat);
|
|
2077
1787
|
}
|
|
2078
|
-
|
|
2079
1788
|
return Array(timesToRepeat).fill(x);
|
|
2080
1789
|
}
|
|
2081
1790
|
|
|
2082
1791
|
function replaceFn(pattern, replacer, str) {
|
|
2083
1792
|
return str.replace(pattern, replacer);
|
|
2084
1793
|
}
|
|
2085
|
-
|
|
2086
1794
|
const replace = curry(replaceFn);
|
|
2087
1795
|
|
|
2088
1796
|
function reverse(listOrString) {
|
|
2089
1797
|
if (typeof listOrString === 'string') {
|
|
2090
1798
|
return listOrString.split('').reverse().join('');
|
|
2091
1799
|
}
|
|
2092
|
-
|
|
2093
1800
|
const clone = listOrString.slice();
|
|
2094
1801
|
return clone.reverse();
|
|
2095
1802
|
}
|
|
@@ -2097,13 +1804,11 @@ function reverse(listOrString) {
|
|
|
2097
1804
|
function setFn(lens, replacer, x) {
|
|
2098
1805
|
return over(lens, always(replacer), x);
|
|
2099
1806
|
}
|
|
2100
|
-
|
|
2101
1807
|
const set = curry(setFn);
|
|
2102
1808
|
|
|
2103
1809
|
function sliceFn(from, to, list) {
|
|
2104
1810
|
return list.slice(from, to);
|
|
2105
1811
|
}
|
|
2106
|
-
|
|
2107
1812
|
const slice = curry(sliceFn);
|
|
2108
1813
|
|
|
2109
1814
|
function sort(sortFn, list) {
|
|
@@ -2144,9 +1849,8 @@ function splitAt(index, input) {
|
|
|
2144
1849
|
if (arguments.length === 1) {
|
|
2145
1850
|
return _list => splitAt(index, _list);
|
|
2146
1851
|
}
|
|
2147
|
-
|
|
2148
1852
|
if (!input) throw new TypeError(`Cannot read property 'slice' of ${input}`);
|
|
2149
|
-
if (!
|
|
1853
|
+
if (!isArray(input) && typeof input !== 'string') return [[], []];
|
|
2150
1854
|
const correctIndex = maybe(index < 0, input.length + index < 0 ? 0 : input.length + index, index);
|
|
2151
1855
|
return [take(correctIndex, input), drop(correctIndex, input)];
|
|
2152
1856
|
}
|
|
@@ -2155,18 +1859,14 @@ function splitEvery(sliceLength, listOrString) {
|
|
|
2155
1859
|
if (arguments.length === 1) {
|
|
2156
1860
|
return _listOrString => splitEvery(sliceLength, _listOrString);
|
|
2157
1861
|
}
|
|
2158
|
-
|
|
2159
1862
|
if (sliceLength < 1) {
|
|
2160
1863
|
throw new Error('First argument to splitEvery must be a positive integer');
|
|
2161
1864
|
}
|
|
2162
|
-
|
|
2163
1865
|
const willReturn = [];
|
|
2164
1866
|
let counter = 0;
|
|
2165
|
-
|
|
2166
1867
|
while (counter < listOrString.length) {
|
|
2167
1868
|
willReturn.push(listOrString.slice(counter, counter += sliceLength));
|
|
2168
1869
|
}
|
|
2169
|
-
|
|
2170
1870
|
return willReturn;
|
|
2171
1871
|
}
|
|
2172
1872
|
|
|
@@ -2174,13 +1874,11 @@ function splitWhen(predicate, input) {
|
|
|
2174
1874
|
if (arguments.length === 1) {
|
|
2175
1875
|
return _input => splitWhen(predicate, _input);
|
|
2176
1876
|
}
|
|
2177
|
-
|
|
2178
1877
|
if (!input) throw new TypeError(`Cannot read property 'length' of ${input}`);
|
|
2179
1878
|
const preFound = [];
|
|
2180
1879
|
const postFound = [];
|
|
2181
1880
|
let found = false;
|
|
2182
1881
|
let counter = -1;
|
|
2183
|
-
|
|
2184
1882
|
while (counter++ < input.length - 1) {
|
|
2185
1883
|
if (found) {
|
|
2186
1884
|
postFound.push(input[counter]);
|
|
@@ -2191,18 +1889,15 @@ function splitWhen(predicate, input) {
|
|
|
2191
1889
|
preFound.push(input[counter]);
|
|
2192
1890
|
}
|
|
2193
1891
|
}
|
|
2194
|
-
|
|
2195
1892
|
return [preFound, postFound];
|
|
2196
1893
|
}
|
|
2197
1894
|
|
|
2198
1895
|
function startsWith(target, iterable) {
|
|
2199
1896
|
if (arguments.length === 1) return _iterable => startsWith(target, _iterable);
|
|
2200
|
-
|
|
2201
1897
|
if (typeof iterable === 'string') {
|
|
2202
1898
|
return iterable.startsWith(target);
|
|
2203
1899
|
}
|
|
2204
|
-
|
|
2205
|
-
if (!_isArray(target)) return false;
|
|
1900
|
+
if (!isArray(target)) return false;
|
|
2206
1901
|
let correct = true;
|
|
2207
1902
|
const filtered = target.filter((x, index) => {
|
|
2208
1903
|
if (!correct) return false;
|
|
@@ -2222,7 +1917,6 @@ function symmetricDifference(x, y) {
|
|
|
2222
1917
|
if (arguments.length === 1) {
|
|
2223
1918
|
return _y => symmetricDifference(x, _y);
|
|
2224
1919
|
}
|
|
2225
|
-
|
|
2226
1920
|
return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
|
|
2227
1921
|
}
|
|
2228
1922
|
|
|
@@ -2244,40 +1938,32 @@ function takeLastWhile(predicate, input) {
|
|
|
2244
1938
|
if (arguments.length === 1) {
|
|
2245
1939
|
return _input => takeLastWhile(predicate, _input);
|
|
2246
1940
|
}
|
|
2247
|
-
|
|
2248
1941
|
if (input.length === 0) return input;
|
|
2249
1942
|
let found = false;
|
|
2250
1943
|
const toReturn = [];
|
|
2251
1944
|
let counter = input.length;
|
|
2252
|
-
|
|
2253
1945
|
while (!found || counter === 0) {
|
|
2254
1946
|
counter--;
|
|
2255
|
-
|
|
2256
1947
|
if (predicate(input[counter]) === false) {
|
|
2257
1948
|
found = true;
|
|
2258
1949
|
} else if (!found) {
|
|
2259
1950
|
toReturn.push(input[counter]);
|
|
2260
1951
|
}
|
|
2261
1952
|
}
|
|
2262
|
-
|
|
2263
|
-
return _isArray(input) ? toReturn.reverse() : toReturn.reverse().join('');
|
|
1953
|
+
return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('');
|
|
2264
1954
|
}
|
|
2265
1955
|
|
|
2266
1956
|
function takeWhile(predicate, iterable) {
|
|
2267
1957
|
if (arguments.length === 1) {
|
|
2268
1958
|
return _iterable => takeWhile(predicate, _iterable);
|
|
2269
1959
|
}
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
if (!isArray && typeof iterable !== 'string') {
|
|
1960
|
+
const isArray$1 = isArray(iterable);
|
|
1961
|
+
if (!isArray$1 && typeof iterable !== 'string') {
|
|
2274
1962
|
throw new Error('`iterable` is neither list nor a string');
|
|
2275
1963
|
}
|
|
2276
|
-
|
|
2277
1964
|
let flag = true;
|
|
2278
1965
|
const holder = [];
|
|
2279
1966
|
let counter = -1;
|
|
2280
|
-
|
|
2281
1967
|
while (counter++ < iterable.length - 1) {
|
|
2282
1968
|
if (!predicate(iterable[counter])) {
|
|
2283
1969
|
if (flag) flag = false;
|
|
@@ -2285,7 +1971,7 @@ function takeWhile(predicate, iterable) {
|
|
|
2285
1971
|
holder.push(iterable[counter]);
|
|
2286
1972
|
}
|
|
2287
1973
|
}
|
|
2288
|
-
return isArray ? holder : holder.join('');
|
|
1974
|
+
return isArray$1 ? holder : holder.join('');
|
|
2289
1975
|
}
|
|
2290
1976
|
|
|
2291
1977
|
function tap(fn, x) {
|
|
@@ -2296,21 +1982,17 @@ function tap(fn, x) {
|
|
|
2296
1982
|
|
|
2297
1983
|
function test(pattern, str) {
|
|
2298
1984
|
if (arguments.length === 1) return _str => test(pattern, _str);
|
|
2299
|
-
|
|
2300
1985
|
if (typeof pattern === 'string') {
|
|
2301
|
-
throw new TypeError(
|
|
1986
|
+
throw new TypeError(`R.test requires a value of type RegExp as its first argument; received "${pattern}"`);
|
|
2302
1987
|
}
|
|
2303
|
-
|
|
2304
1988
|
return str.search(pattern) !== -1;
|
|
2305
1989
|
}
|
|
2306
1990
|
|
|
2307
1991
|
function times(fn, howMany) {
|
|
2308
1992
|
if (arguments.length === 1) return _howMany => times(fn, _howMany);
|
|
2309
|
-
|
|
2310
|
-
if (!Number.isInteger(howMany) || howMany < 0) {
|
|
1993
|
+
if (!isInteger(howMany) || howMany < 0) {
|
|
2311
1994
|
throw new RangeError('n must be an integer');
|
|
2312
1995
|
}
|
|
2313
|
-
|
|
2314
1996
|
return map(fn, range(0, howMany));
|
|
2315
1997
|
}
|
|
2316
1998
|
|
|
@@ -2332,7 +2014,7 @@ function toUpper(str) {
|
|
|
2332
2014
|
|
|
2333
2015
|
function transpose(array) {
|
|
2334
2016
|
return array.reduce((acc, el) => {
|
|
2335
|
-
el.forEach((nestedEl, i) =>
|
|
2017
|
+
el.forEach((nestedEl, i) => isArray(acc[i]) ? acc[i].push(nestedEl) : acc.push([nestedEl]));
|
|
2336
2018
|
return acc;
|
|
2337
2019
|
}, []);
|
|
2338
2020
|
}
|
|
@@ -2342,12 +2024,10 @@ function trim(str) {
|
|
|
2342
2024
|
}
|
|
2343
2025
|
|
|
2344
2026
|
const isFunction = x => ['Promise', 'Function'].includes(type(x));
|
|
2345
|
-
|
|
2346
2027
|
function tryCatch(fn, fallback) {
|
|
2347
2028
|
if (!isFunction(fn)) {
|
|
2348
2029
|
throw new Error(`R.tryCatch | fn '${fn}'`);
|
|
2349
2030
|
}
|
|
2350
|
-
|
|
2351
2031
|
const passFallback = isFunction(fallback);
|
|
2352
2032
|
return (...inputs) => {
|
|
2353
2033
|
try {
|
|
@@ -2377,7 +2057,6 @@ function uniqBy(fn, list) {
|
|
|
2377
2057
|
if (arguments.length === 1) {
|
|
2378
2058
|
return _list => uniqBy(fn, _list);
|
|
2379
2059
|
}
|
|
2380
|
-
|
|
2381
2060
|
const set = new Set();
|
|
2382
2061
|
return list.filter(item => {
|
|
2383
2062
|
if (set.has(fn(item))) return false;
|
|
@@ -2389,31 +2068,24 @@ function uniqBy(fn, list) {
|
|
|
2389
2068
|
function includesWith(predicate, target, list) {
|
|
2390
2069
|
let willReturn = false;
|
|
2391
2070
|
let index = -1;
|
|
2392
|
-
|
|
2393
2071
|
while (++index < list.length && !willReturn) {
|
|
2394
2072
|
const value = list[index];
|
|
2395
|
-
|
|
2396
2073
|
if (predicate(target, value)) {
|
|
2397
2074
|
willReturn = true;
|
|
2398
2075
|
}
|
|
2399
2076
|
}
|
|
2400
|
-
|
|
2401
2077
|
return willReturn;
|
|
2402
2078
|
}
|
|
2403
|
-
|
|
2404
2079
|
function uniqWith(predicate, list) {
|
|
2405
2080
|
if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
|
2406
2081
|
let index = -1;
|
|
2407
2082
|
const willReturn = [];
|
|
2408
|
-
|
|
2409
2083
|
while (++index < list.length) {
|
|
2410
2084
|
const value = list[index];
|
|
2411
|
-
|
|
2412
2085
|
if (!includesWith(predicate, value, willReturn)) {
|
|
2413
2086
|
willReturn.push(value);
|
|
2414
2087
|
}
|
|
2415
2088
|
}
|
|
2416
|
-
|
|
2417
2089
|
return willReturn;
|
|
2418
2090
|
}
|
|
2419
2091
|
|
|
@@ -2421,7 +2093,6 @@ function unless(predicate, whenFalse) {
|
|
|
2421
2093
|
if (arguments.length === 1) {
|
|
2422
2094
|
return _whenFalse => unless(predicate, _whenFalse);
|
|
2423
2095
|
}
|
|
2424
|
-
|
|
2425
2096
|
return input => predicate(input) ? input : whenFalse(input);
|
|
2426
2097
|
}
|
|
2427
2098
|
|
|
@@ -2429,8 +2100,7 @@ function unwind(property, obj) {
|
|
|
2429
2100
|
if (arguments.length === 1) {
|
|
2430
2101
|
return _obj => unwind(property, _obj);
|
|
2431
2102
|
}
|
|
2432
|
-
|
|
2433
|
-
if (!_isArray(obj[property])) return [obj];
|
|
2103
|
+
if (!isArray(obj[property])) return [obj];
|
|
2434
2104
|
return mapArray(x => _objectSpread2(_objectSpread2({}, obj), {}, {
|
|
2435
2105
|
[property]: x
|
|
2436
2106
|
}), obj[property]);
|
|
@@ -2445,7 +2115,6 @@ const Const = x => ({
|
|
|
2445
2115
|
x,
|
|
2446
2116
|
map: fn => Const(x)
|
|
2447
2117
|
});
|
|
2448
|
-
|
|
2449
2118
|
function view(lens, target) {
|
|
2450
2119
|
if (arguments.length === 1) return _target => view(lens, _target);
|
|
2451
2120
|
return lens(Const)(target).x;
|
|
@@ -2455,24 +2124,20 @@ function whenFn(predicate, whenTrueFn, input) {
|
|
|
2455
2124
|
if (!predicate(input)) return input;
|
|
2456
2125
|
return whenTrueFn(input);
|
|
2457
2126
|
}
|
|
2458
|
-
|
|
2459
2127
|
const when = curry(whenFn);
|
|
2460
2128
|
|
|
2461
2129
|
function where(conditions, input) {
|
|
2462
2130
|
if (input === undefined) {
|
|
2463
2131
|
return _input => where(conditions, _input);
|
|
2464
2132
|
}
|
|
2465
|
-
|
|
2466
2133
|
let flag = true;
|
|
2467
|
-
|
|
2468
2134
|
for (const prop in conditions) {
|
|
2135
|
+
if (!flag) continue;
|
|
2469
2136
|
const result = conditions[prop](input[prop]);
|
|
2470
|
-
|
|
2471
2137
|
if (flag && result === false) {
|
|
2472
2138
|
flag = false;
|
|
2473
2139
|
}
|
|
2474
2140
|
}
|
|
2475
|
-
|
|
2476
2141
|
return flag;
|
|
2477
2142
|
}
|
|
2478
2143
|
|
|
@@ -2480,13 +2145,11 @@ function whereAny(conditions, input) {
|
|
|
2480
2145
|
if (input === undefined) {
|
|
2481
2146
|
return _input => whereAny(conditions, _input);
|
|
2482
2147
|
}
|
|
2483
|
-
|
|
2484
2148
|
for (const prop in conditions) {
|
|
2485
2149
|
if (conditions[prop](input[prop])) {
|
|
2486
2150
|
return true;
|
|
2487
2151
|
}
|
|
2488
2152
|
}
|
|
2489
|
-
|
|
2490
2153
|
return false;
|
|
2491
2154
|
}
|
|
2492
2155
|
|
|
@@ -2494,7 +2157,6 @@ function whereEq(condition, input) {
|
|
|
2494
2157
|
if (arguments.length === 1) {
|
|
2495
2158
|
return _input => whereEq(condition, _input);
|
|
2496
2159
|
}
|
|
2497
|
-
|
|
2498
2160
|
const result = filter((conditionValue, conditionProp) => equals(conditionValue, input[conditionProp]), condition);
|
|
2499
2161
|
return Object.keys(result).length === Object.keys(condition).length;
|
|
2500
2162
|
}
|
|
@@ -2503,7 +2165,6 @@ function without(matchAgainst, source) {
|
|
|
2503
2165
|
if (source === undefined) {
|
|
2504
2166
|
return _source => without(matchAgainst, _source);
|
|
2505
2167
|
}
|
|
2506
|
-
|
|
2507
2168
|
return reduce((prev, current) => _indexOf(current, matchAgainst) > -1 ? prev : prev.concat(current), [], source);
|
|
2508
2169
|
}
|
|
2509
2170
|
|
|
@@ -2516,11 +2177,9 @@ function zip(left, right) {
|
|
|
2516
2177
|
if (arguments.length === 1) return _right => zip(left, _right);
|
|
2517
2178
|
const result = [];
|
|
2518
2179
|
const length = Math.min(left.length, right.length);
|
|
2519
|
-
|
|
2520
2180
|
for (let i = 0; i < length; i++) {
|
|
2521
2181
|
result[i] = [left[i], right[i]];
|
|
2522
2182
|
}
|
|
2523
|
-
|
|
2524
2183
|
return result;
|
|
2525
2184
|
}
|
|
2526
2185
|
|
|
@@ -2535,7 +2194,6 @@ function zipObj(keys, values) {
|
|
|
2535
2194
|
function zipWithFn(fn, x, y) {
|
|
2536
2195
|
return take(x.length > y.length ? y.length : x.length, x).map((xInstance, i) => fn(xInstance, y[i]));
|
|
2537
2196
|
}
|
|
2538
|
-
|
|
2539
2197
|
const zipWith = curry(zipWithFn);
|
|
2540
2198
|
|
|
2541
2199
|
exports.F = F;
|
|
@@ -2649,6 +2307,7 @@ exports.mergeWith = mergeWith;
|
|
|
2649
2307
|
exports.min = min;
|
|
2650
2308
|
exports.minBy = minBy;
|
|
2651
2309
|
exports.minByFn = minByFn;
|
|
2310
|
+
exports.modify = modify;
|
|
2652
2311
|
exports.modifyPath = modifyPath;
|
|
2653
2312
|
exports.modifyPathFn = modifyPathFn;
|
|
2654
2313
|
exports.modulo = modulo;
|
|
@@ -2656,6 +2315,7 @@ exports.move = move;
|
|
|
2656
2315
|
exports.multiply = multiply;
|
|
2657
2316
|
exports.negate = negate;
|
|
2658
2317
|
exports.none = none;
|
|
2318
|
+
exports.nop = nop;
|
|
2659
2319
|
exports.not = not;
|
|
2660
2320
|
exports.nth = nth;
|
|
2661
2321
|
exports.objOf = objOf;
|
|
@@ -2730,6 +2390,7 @@ exports.uniqWith = uniqWith;
|
|
|
2730
2390
|
exports.unless = unless;
|
|
2731
2391
|
exports.unwind = unwind;
|
|
2732
2392
|
exports.update = update;
|
|
2393
|
+
exports.updateFn = updateFn;
|
|
2733
2394
|
exports.values = values;
|
|
2734
2395
|
exports.view = view;
|
|
2735
2396
|
exports.when = when;
|