rambda 6.8.1 → 7.0.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 +93 -0
- package/README.md +4108 -5600
- package/dist/rambda.esm.js +340 -212
- package/dist/rambda.js +345 -212
- package/dist/rambda.mjs +340 -212
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +202 -275
- package/immutable.js +1 -0
- package/index.d.ts +202 -275
- package/package.json +111 -94
- package/src/F.js +1 -1
- package/src/T.js +1 -1
- package/src/_internals/_isInteger.js +1 -1
- package/src/_internals/_objectIs.js +2 -2
- package/src/_internals/baseSlice.js +6 -8
- package/src/_internals/cloneList.js +3 -0
- package/src/_internals/isFalsy.js +5 -5
- package/src/_internals/isObject.js +5 -0
- package/src/_internals/isTruthy.js +5 -5
- package/src/_internals/set.js +35 -0
- package/src/add.js +1 -1
- package/src/adjust.js +5 -6
- package/src/all.js +3 -3
- package/src/allPass.js +4 -4
- package/src/always.js +1 -1
- package/src/and.js +1 -1
- package/src/any.js +3 -3
- package/src/anyPass.js +4 -4
- package/src/append.js +4 -2
- package/src/apply.js +7 -0
- package/src/applySpec.js +33 -59
- package/src/assoc.js +3 -7
- package/src/assocPath.js +22 -25
- package/src/bind.js +9 -0
- package/src/both.js +1 -1
- package/src/chain.js +2 -2
- package/src/clamp.js +6 -6
- package/src/clone.js +10 -10
- package/src/complement.js +1 -1
- package/src/compose.js +6 -6
- package/src/concat.js +2 -2
- package/src/cond.js +3 -3
- package/src/converge.js +11 -11
- package/src/curry.js +2 -2
- package/src/curryN.js +61 -81
- package/src/defaultTo.js +5 -8
- package/src/difference.js +3 -3
- package/src/dissoc.js +4 -4
- package/src/divide.js +1 -1
- package/src/drop.js +1 -1
- package/src/dropLast.js +5 -5
- package/src/dropLastWhile.js +12 -12
- package/src/dropRepeats.js +6 -6
- package/src/dropRepeatsWith.js +7 -7
- package/src/dropWhile.js +9 -9
- package/src/either.js +2 -2
- package/src/endsWith.js +20 -3
- package/src/eqProps.js +5 -10
- package/src/equals.js +119 -38
- package/src/evolve.js +23 -21
- package/src/filter.js +17 -19
- package/src/find.js +4 -4
- package/src/findIndex.js +3 -3
- package/src/findLast.js +4 -4
- package/src/findLastIndex.js +3 -3
- package/src/flatten.js +6 -6
- package/src/flip.js +11 -15
- package/src/forEach.js +10 -12
- package/src/fromPairs.js +2 -2
- package/src/groupBy.js +6 -6
- package/src/groupWith.js +11 -12
- package/src/hasPath.js +5 -5
- package/src/head.js +3 -3
- package/src/identical.js +1 -1
- package/src/identity.js +2 -2
- package/src/ifElse.js +3 -5
- package/src/includes.js +11 -22
- package/src/indexBy.js +11 -11
- package/src/indexOf.js +5 -12
- package/src/init.js +2 -4
- package/src/intersection.js +3 -3
- package/src/intersperse.js +5 -5
- package/src/is.js +2 -2
- package/src/isEmpty.js +5 -5
- package/src/isFunction.js +3 -3
- package/src/isNil.js +1 -1
- package/src/isPromise.js +3 -3
- package/src/join.js +1 -1
- package/src/keys.js +1 -1
- package/src/last.js +4 -4
- package/src/lastIndexOf.js +5 -11
- package/src/length.js +6 -5
- package/src/lens.js +3 -3
- package/src/lensIndex.js +4 -4
- package/src/lensProp.js +4 -4
- package/src/map.js +19 -18
- package/src/match.js +1 -1
- package/src/mathMod.js +2 -2
- package/src/max.js +1 -1
- package/src/maxBy.js +2 -4
- package/src/maybe.js +2 -4
- package/src/mean.js +2 -2
- package/src/median.js +12 -10
- package/src/merge.js +2 -4
- package/src/mergeAll.js +3 -3
- package/src/mergeDeepRight.js +8 -8
- package/src/mergeLeft.js +2 -2
- package/src/min.js +1 -1
- package/src/minBy.js +2 -4
- package/src/modulo.js +1 -1
- package/src/move.js +7 -8
- package/src/multiply.js +1 -1
- package/src/negate.js +1 -1
- package/src/none.js +3 -3
- package/src/not.js +1 -1
- package/src/nth.js +4 -4
- package/src/objOf.js +3 -3
- package/src/of.js +2 -2
- package/src/omit.js +5 -5
- package/src/once.js +6 -6
- package/src/or.js +1 -1
- package/src/over.js +3 -5
- package/src/partial.js +3 -3
- package/src/partition.js +17 -15
- package/src/path.js +6 -6
- package/src/pathEq.js +4 -6
- package/src/pathOr.js +5 -7
- package/src/paths.js +3 -3
- package/src/pick.js +5 -5
- package/src/pickAll.js +6 -6
- package/src/pipe.js +3 -3
- package/src/pluck.js +4 -4
- package/src/prepend.js +3 -3
- package/src/product.js +2 -2
- package/src/prop.js +2 -2
- package/src/propEq.js +3 -5
- package/src/propIs.js +4 -6
- package/src/propOr.js +4 -6
- package/src/props.js +6 -6
- package/src/range.js +4 -4
- package/src/reduce.js +7 -11
- package/src/reject.js +2 -2
- package/src/repeat.js +2 -2
- package/src/replace.js +2 -4
- package/src/reverse.js +3 -4
- package/src/set.js +5 -9
- package/src/slice.js +2 -4
- package/src/sort.js +4 -4
- package/src/sortBy.js +4 -2
- package/src/split.js +1 -1
- package/src/splitAt.js +9 -9
- package/src/splitEvery.js +8 -6
- package/src/splitWhen.js +10 -10
- package/src/startsWith.js +20 -3
- package/src/subtract.js +1 -1
- package/src/sum.js +1 -1
- package/src/symmetricDifference.js +9 -7
- package/src/tail.js +2 -2
- package/src/take.js +2 -4
- package/src/takeLast.js +2 -4
- package/src/takeLastWhile.js +7 -7
- package/src/takeWhile.js +8 -8
- package/src/tap.js +1 -1
- package/src/test.js +5 -3
- package/src/times.js +4 -4
- package/src/toLower.js +1 -1
- package/src/toPairs.js +1 -1
- package/src/toString.js +1 -1
- package/src/toUpper.js +1 -1
- package/src/transpose.js +4 -3
- package/src/trim.js +1 -1
- package/src/tryCatch.js +5 -5
- package/src/type.js +7 -29
- package/src/unapply.js +5 -0
- package/src/union.js +4 -3
- package/src/uniq.js +7 -10
- package/src/uniqWith.js +18 -7
- package/src/unless.js +3 -3
- package/src/update.js +6 -8
- package/src/values.js +2 -2
- package/src/view.js +2 -2
- package/src/when.js +2 -4
- package/src/where.js +5 -5
- package/src/whereEq.js +9 -7
- package/src/without.js +5 -5
- package/src/xor.js +2 -2
- package/src/zip.js +3 -3
- package/src/zipObj.js +4 -6
- package/src/zipWith.js +6 -7
package/dist/rambda.esm.js
CHANGED
|
@@ -15,10 +15,14 @@ function curry(fn, args = []) {
|
|
|
15
15
|
return (..._args) => (rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const cloneList = list => {
|
|
19
|
+
return Array.prototype.slice.call(list);
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
function adjustFn(index, replaceFn, list) {
|
|
19
23
|
const actualIndex = index < 0 ? list.length + index : index;
|
|
20
24
|
if (index >= list.length || actualIndex < 0) return list;
|
|
21
|
-
const clone = list
|
|
25
|
+
const clone = cloneList(list);
|
|
22
26
|
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
23
27
|
return clone;
|
|
24
28
|
}
|
|
@@ -36,11 +40,11 @@ function all(predicate, list) {
|
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
function allPass(predicates) {
|
|
39
|
-
return input => {
|
|
43
|
+
return (...input) => {
|
|
40
44
|
let counter = 0;
|
|
41
45
|
|
|
42
46
|
while (counter < predicates.length) {
|
|
43
|
-
if (!predicates[counter](input)) {
|
|
47
|
+
if (!predicates[counter](...input)) {
|
|
44
48
|
return false;
|
|
45
49
|
}
|
|
46
50
|
|
|
@@ -76,11 +80,11 @@ function any(predicate, list) {
|
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
function anyPass(predicates) {
|
|
79
|
-
return input => {
|
|
83
|
+
return (...input) => {
|
|
80
84
|
let counter = 0;
|
|
81
85
|
|
|
82
86
|
while (counter < predicates.length) {
|
|
83
|
-
if (predicates[counter](input)) {
|
|
87
|
+
if (predicates[counter](...input)) {
|
|
84
88
|
return true;
|
|
85
89
|
}
|
|
86
90
|
|
|
@@ -94,11 +98,19 @@ function anyPass(predicates) {
|
|
|
94
98
|
function append(x, input) {
|
|
95
99
|
if (arguments.length === 1) return _input => append(x, _input);
|
|
96
100
|
if (typeof input === 'string') return input.split('').concat(x);
|
|
97
|
-
const clone = input
|
|
101
|
+
const clone = cloneList(input);
|
|
98
102
|
clone.push(x);
|
|
99
103
|
return clone;
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
function apply(fn, args) {
|
|
107
|
+
if (arguments.length === 1) {
|
|
108
|
+
return _args => apply(fn, _args);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return fn.apply(this, args);
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
const _isArray = Array.isArray;
|
|
103
115
|
|
|
104
116
|
function __findHighestArity(spec, max = 0) {
|
|
@@ -216,7 +228,7 @@ function assocPathFn(path, newValue, input) {
|
|
|
216
228
|
}
|
|
217
229
|
|
|
218
230
|
if (_isInteger(index) && _isArray(input)) {
|
|
219
|
-
const arr = input
|
|
231
|
+
const arr = cloneList(input);
|
|
220
232
|
arr[index] = newValue;
|
|
221
233
|
return arr;
|
|
222
234
|
}
|
|
@@ -226,87 +238,6 @@ function assocPathFn(path, newValue, input) {
|
|
|
226
238
|
|
|
227
239
|
const assocPath = curry(assocPathFn);
|
|
228
240
|
|
|
229
|
-
function both(f, g) {
|
|
230
|
-
if (arguments.length === 1) return _g => both(f, _g);
|
|
231
|
-
return (...input) => f(...input) && g(...input);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function chain(fn, list) {
|
|
235
|
-
if (arguments.length === 1) {
|
|
236
|
-
return _list => chain(fn, _list);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
return [].concat(...list.map(fn));
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function clampFn(min, max, input) {
|
|
243
|
-
if (min > max) {
|
|
244
|
-
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (input >= min && input <= max) return input;
|
|
248
|
-
if (input > max) return max;
|
|
249
|
-
if (input < min) return min;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const clamp = curry(clampFn);
|
|
253
|
-
|
|
254
|
-
function clone(input) {
|
|
255
|
-
const out = _isArray(input) ? Array(input.length) : {};
|
|
256
|
-
if (input && input.getTime) return new Date(input.getTime());
|
|
257
|
-
|
|
258
|
-
for (const key in input) {
|
|
259
|
-
const v = input[key];
|
|
260
|
-
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
return out;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function complement(fn) {
|
|
267
|
-
return (...input) => !fn(...input);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function compose(...fns) {
|
|
271
|
-
if (fns.length === 0) {
|
|
272
|
-
throw new Error('compose requires at least one argument');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return (...args) => {
|
|
276
|
-
const list = fns.slice();
|
|
277
|
-
|
|
278
|
-
if (list.length > 0) {
|
|
279
|
-
const fn = list.pop();
|
|
280
|
-
let result = fn(...args);
|
|
281
|
-
|
|
282
|
-
while (list.length > 0) {
|
|
283
|
-
result = list.pop()(result);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return result;
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function concat(x, y) {
|
|
292
|
-
if (arguments.length === 1) return _y => concat(x, _y);
|
|
293
|
-
return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
function cond(conditions) {
|
|
297
|
-
return input => {
|
|
298
|
-
let done = false;
|
|
299
|
-
let toReturn;
|
|
300
|
-
conditions.forEach(([predicate, resultClosure]) => {
|
|
301
|
-
if (!done && predicate(input)) {
|
|
302
|
-
done = true;
|
|
303
|
-
toReturn = resultClosure(input);
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
return toReturn;
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
241
|
function _curryN(n, cache, fn) {
|
|
311
242
|
return function () {
|
|
312
243
|
let ci = 0;
|
|
@@ -399,6 +330,95 @@ function curryN(n, fn) {
|
|
|
399
330
|
return _arity(n, _curryN(n, [], fn));
|
|
400
331
|
}
|
|
401
332
|
|
|
333
|
+
function bind(fn, thisObj) {
|
|
334
|
+
if (arguments.length === 1) {
|
|
335
|
+
return _thisObj => bind(fn, _thisObj);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return curryN(fn.length, (...args) => fn.apply(thisObj, args));
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function both(f, g) {
|
|
342
|
+
if (arguments.length === 1) return _g => both(f, _g);
|
|
343
|
+
return (...input) => f(...input) && g(...input);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function chain(fn, list) {
|
|
347
|
+
if (arguments.length === 1) {
|
|
348
|
+
return _list => chain(fn, _list);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return [].concat(...list.map(fn));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function clampFn(min, max, input) {
|
|
355
|
+
if (min > max) {
|
|
356
|
+
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (input >= min && input <= max) return input;
|
|
360
|
+
if (input > max) return max;
|
|
361
|
+
if (input < min) return min;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const clamp = curry(clampFn);
|
|
365
|
+
|
|
366
|
+
function clone(input) {
|
|
367
|
+
const out = _isArray(input) ? Array(input.length) : {};
|
|
368
|
+
if (input && input.getTime) return new Date(input.getTime());
|
|
369
|
+
|
|
370
|
+
for (const key in input) {
|
|
371
|
+
const v = input[key];
|
|
372
|
+
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return out;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function complement(fn) {
|
|
379
|
+
return (...input) => !fn(...input);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function compose(...fns) {
|
|
383
|
+
if (fns.length === 0) {
|
|
384
|
+
throw new Error('compose requires at least one argument');
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return function (...args) {
|
|
388
|
+
const list = fns.slice();
|
|
389
|
+
|
|
390
|
+
if (list.length > 0) {
|
|
391
|
+
const fn = list.pop();
|
|
392
|
+
let result = fn.apply(this, args);
|
|
393
|
+
|
|
394
|
+
while (list.length > 0) {
|
|
395
|
+
result = list.pop()(result);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function concat(x, y) {
|
|
404
|
+
if (arguments.length === 1) return _y => concat(x, _y);
|
|
405
|
+
return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function cond(conditions) {
|
|
409
|
+
return input => {
|
|
410
|
+
let done = false;
|
|
411
|
+
let toReturn;
|
|
412
|
+
conditions.forEach(([predicate, resultClosure]) => {
|
|
413
|
+
if (!done && predicate(input)) {
|
|
414
|
+
done = true;
|
|
415
|
+
toReturn = resultClosure(input);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
return toReturn;
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
402
422
|
const _keys = Object.keys;
|
|
403
423
|
|
|
404
424
|
function mapArray(fn, list, isIndexed = false) {
|
|
@@ -428,11 +448,16 @@ function mapObject(fn, obj) {
|
|
|
428
448
|
|
|
429
449
|
return willReturn;
|
|
430
450
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (
|
|
434
|
-
|
|
435
|
-
|
|
451
|
+
const mapObjIndexed = mapObject;
|
|
452
|
+
function map(fn, iterable) {
|
|
453
|
+
if (arguments.length === 1) return _iterable => map(fn, _iterable);
|
|
454
|
+
|
|
455
|
+
if (!iterable) {
|
|
456
|
+
throw new Error('Incorrect iterable input');
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (_isArray(iterable)) return mapArray(fn, iterable);
|
|
460
|
+
return mapObject(fn, iterable);
|
|
436
461
|
}
|
|
437
462
|
|
|
438
463
|
function max(x, y) {
|
|
@@ -481,34 +506,83 @@ function defaultTo(defaultArgument, input) {
|
|
|
481
506
|
}
|
|
482
507
|
|
|
483
508
|
function type(input) {
|
|
484
|
-
const typeOf = typeof input;
|
|
485
|
-
|
|
486
509
|
if (input === null) {
|
|
487
510
|
return 'Null';
|
|
488
511
|
} else if (input === undefined) {
|
|
489
512
|
return 'Undefined';
|
|
490
|
-
} else if (
|
|
491
|
-
return '
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
} else if (Number.isNaN(input)) {
|
|
514
|
+
return 'NaN';
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
const typeResult = Object.prototype.toString.call(input).slice(8, -1);
|
|
518
|
+
return typeResult === 'AsyncFunction' ? 'Async' : typeResult;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function _lastIndexOf(valueToFind, list) {
|
|
522
|
+
if (!_isArray(list)) {
|
|
523
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
const typeOfValue = type(valueToFind);
|
|
527
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.lastIndexOf(valueToFind);
|
|
528
|
+
const {
|
|
529
|
+
length
|
|
530
|
+
} = list;
|
|
531
|
+
let index = length;
|
|
532
|
+
let foundIndex = -1;
|
|
533
|
+
|
|
534
|
+
while (--index > -1 && foundIndex === -1) {
|
|
535
|
+
if (equals(list[index], valueToFind)) {
|
|
536
|
+
foundIndex = index;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return foundIndex;
|
|
541
|
+
}
|
|
542
|
+
function _indexOf(valueToFind, list) {
|
|
543
|
+
if (!_isArray(list)) {
|
|
544
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const typeOfValue = type(valueToFind);
|
|
548
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.indexOf(valueToFind);
|
|
549
|
+
let index = -1;
|
|
550
|
+
let foundIndex = -1;
|
|
551
|
+
const {
|
|
552
|
+
length
|
|
553
|
+
} = list;
|
|
554
|
+
|
|
555
|
+
while (++index < length && foundIndex === -1) {
|
|
556
|
+
if (equals(list[index], valueToFind)) {
|
|
557
|
+
foundIndex = index;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return foundIndex;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function _arrayFromIterator(iter) {
|
|
565
|
+
const list = [];
|
|
566
|
+
let next;
|
|
567
|
+
|
|
568
|
+
while (!(next = iter.next()).done) {
|
|
569
|
+
list.push(next.value);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
return list;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function _equalsSets(a, b) {
|
|
576
|
+
if (a.size !== b.size) {
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const aList = _arrayFromIterator(a.values());
|
|
581
|
+
|
|
582
|
+
const bList = _arrayFromIterator(b.values());
|
|
583
|
+
|
|
584
|
+
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1);
|
|
585
|
+
return filtered.length === 0;
|
|
512
586
|
}
|
|
513
587
|
|
|
514
588
|
function parseError(maybeError) {
|
|
@@ -588,6 +662,10 @@ function equals(a, b) {
|
|
|
588
662
|
return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
|
589
663
|
}
|
|
590
664
|
|
|
665
|
+
if (aType === 'Set') {
|
|
666
|
+
return _equalsSets(a, b);
|
|
667
|
+
}
|
|
668
|
+
|
|
591
669
|
if (aType === 'Object') {
|
|
592
670
|
const aKeys = Object.keys(a);
|
|
593
671
|
|
|
@@ -612,44 +690,68 @@ function equals(a, b) {
|
|
|
612
690
|
return false;
|
|
613
691
|
}
|
|
614
692
|
|
|
615
|
-
function
|
|
616
|
-
|
|
693
|
+
function includes(valueToFind, iterable) {
|
|
694
|
+
if (arguments.length === 1) return _iterable => includes(valueToFind, _iterable);
|
|
617
695
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
return true;
|
|
621
|
-
}
|
|
696
|
+
if (typeof iterable === 'string') {
|
|
697
|
+
return iterable.includes(valueToFind);
|
|
622
698
|
}
|
|
623
699
|
|
|
624
|
-
|
|
700
|
+
if (!iterable) {
|
|
701
|
+
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (!_isArray(iterable)) return false;
|
|
705
|
+
return _indexOf(valueToFind, iterable) > -1;
|
|
625
706
|
}
|
|
626
|
-
function includes(valueToFind, input) {
|
|
627
|
-
if (arguments.length === 1) return _input => includes(valueToFind, _input);
|
|
628
707
|
|
|
629
|
-
|
|
630
|
-
|
|
708
|
+
class _Set {
|
|
709
|
+
constructor() {
|
|
710
|
+
this.set = new Set();
|
|
711
|
+
this.items = {};
|
|
631
712
|
}
|
|
632
713
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}
|
|
714
|
+
checkUniqueness(item) {
|
|
715
|
+
const type$1 = type(item);
|
|
636
716
|
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
717
|
+
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
718
|
+
if (type$1 in this.items) {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
640
721
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
722
|
+
this.items[type$1] = true;
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
644
725
|
|
|
645
|
-
|
|
646
|
-
|
|
726
|
+
if (!['Object', 'Array'].includes(type$1)) {
|
|
727
|
+
const prevSize = this.set.size;
|
|
728
|
+
this.set.add(item);
|
|
729
|
+
return this.set.size !== prevSize;
|
|
730
|
+
}
|
|
647
731
|
|
|
648
|
-
if (!
|
|
649
|
-
|
|
732
|
+
if (!(type$1 in this.items)) {
|
|
733
|
+
this.items[type$1] = [item];
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
738
|
+
this.items[type$1].push(item);
|
|
739
|
+
return true;
|
|
650
740
|
}
|
|
741
|
+
|
|
742
|
+
return false;
|
|
651
743
|
}
|
|
652
744
|
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function uniq(list) {
|
|
748
|
+
const set = new _Set();
|
|
749
|
+
const willReturn = [];
|
|
750
|
+
list.forEach(item => {
|
|
751
|
+
if (set.checkUniqueness(item)) {
|
|
752
|
+
willReturn.push(item);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
653
755
|
return willReturn;
|
|
654
756
|
}
|
|
655
757
|
|
|
@@ -800,17 +902,33 @@ function either(firstPredicate, secondPredicate) {
|
|
|
800
902
|
return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
|
801
903
|
}
|
|
802
904
|
|
|
803
|
-
function endsWith(target,
|
|
804
|
-
if (arguments.length === 1) return
|
|
805
|
-
return str.endsWith(target);
|
|
806
|
-
}
|
|
905
|
+
function endsWith(target, iterable) {
|
|
906
|
+
if (arguments.length === 1) return _iterable => endsWith(target, _iterable);
|
|
807
907
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
throw new Error('wrong object inputs are passed to R.eqProps');
|
|
908
|
+
if (typeof iterable === 'string') {
|
|
909
|
+
return iterable.endsWith(target);
|
|
811
910
|
}
|
|
812
911
|
|
|
813
|
-
|
|
912
|
+
if (!_isArray(target)) return false;
|
|
913
|
+
const diff = iterable.length - target.length;
|
|
914
|
+
let correct = true;
|
|
915
|
+
const filtered = target.filter((x, index) => {
|
|
916
|
+
if (!correct) return false;
|
|
917
|
+
const result = equals(x, iterable[index + diff]);
|
|
918
|
+
if (!result) correct = false;
|
|
919
|
+
return result;
|
|
920
|
+
});
|
|
921
|
+
return filtered.length === target.length;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
function prop(propToFind, obj) {
|
|
925
|
+
if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
|
926
|
+
if (!obj) return undefined;
|
|
927
|
+
return obj[propToFind];
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function eqPropsFn(property, objA, objB) {
|
|
931
|
+
return equals(prop(property, objA), prop(property, objB));
|
|
814
932
|
}
|
|
815
933
|
|
|
816
934
|
const eqProps = curry(eqPropsFn);
|
|
@@ -870,11 +988,11 @@ function evolve(rules, iterable) {
|
|
|
870
988
|
return evolveArray(rules, iterable);
|
|
871
989
|
}
|
|
872
990
|
|
|
873
|
-
function filterObject(
|
|
991
|
+
function filterObject(predicate, obj) {
|
|
874
992
|
const willReturn = {};
|
|
875
993
|
|
|
876
994
|
for (const prop in obj) {
|
|
877
|
-
if (
|
|
995
|
+
if (predicate(obj[prop], prop, obj)) {
|
|
878
996
|
willReturn[prop] = obj[prop];
|
|
879
997
|
}
|
|
880
998
|
}
|
|
@@ -899,11 +1017,12 @@ function filterArray(predicate, list, indexed = false) {
|
|
|
899
1017
|
return willReturn;
|
|
900
1018
|
}
|
|
901
1019
|
function filter(predicate, iterable) {
|
|
902
|
-
if (arguments.length === 1)
|
|
903
|
-
|
|
1020
|
+
if (arguments.length === 1) return _iterable => filter(predicate, _iterable);
|
|
1021
|
+
|
|
1022
|
+
if (!iterable) {
|
|
1023
|
+
throw new Error('Incorrect iterable input');
|
|
904
1024
|
}
|
|
905
1025
|
|
|
906
|
-
if (!iterable) return [];
|
|
907
1026
|
if (_isArray(iterable)) return filterArray(predicate, iterable);
|
|
908
1027
|
return filterObject(predicate, iterable);
|
|
909
1028
|
}
|
|
@@ -990,7 +1109,7 @@ function flipFn(fn) {
|
|
|
990
1109
|
return fn(input[1], input[0], input[2], input[3]);
|
|
991
1110
|
}
|
|
992
1111
|
|
|
993
|
-
throw new Error(
|
|
1112
|
+
throw new Error("R.flip doesn't work with arity > 4");
|
|
994
1113
|
};
|
|
995
1114
|
}
|
|
996
1115
|
|
|
@@ -1056,7 +1175,7 @@ function groupBy(groupFn, list) {
|
|
|
1056
1175
|
|
|
1057
1176
|
function groupWith(compareFn, list) {
|
|
1058
1177
|
if (!_isArray(list)) throw new TypeError('list.reduce is not a function');
|
|
1059
|
-
const clone = list
|
|
1178
|
+
const clone = cloneList(list);
|
|
1060
1179
|
if (list.length === 1) return [clone];
|
|
1061
1180
|
const toReturn = [];
|
|
1062
1181
|
let holder = [];
|
|
@@ -1117,12 +1236,12 @@ function path(pathInput, obj) {
|
|
|
1117
1236
|
return willReturn;
|
|
1118
1237
|
}
|
|
1119
1238
|
|
|
1120
|
-
function hasPath(
|
|
1239
|
+
function hasPath(pathInput, obj) {
|
|
1121
1240
|
if (arguments.length === 1) {
|
|
1122
|
-
return objHolder => hasPath(
|
|
1241
|
+
return objHolder => hasPath(pathInput, objHolder);
|
|
1123
1242
|
}
|
|
1124
1243
|
|
|
1125
|
-
return path(
|
|
1244
|
+
return path(pathInput, obj) !== undefined;
|
|
1126
1245
|
}
|
|
1127
1246
|
|
|
1128
1247
|
function head(listOrString) {
|
|
@@ -1144,8 +1263,8 @@ function identical(a, b) {
|
|
|
1144
1263
|
return _objectIs$1(a, b);
|
|
1145
1264
|
}
|
|
1146
1265
|
|
|
1147
|
-
function identity(
|
|
1148
|
-
return
|
|
1266
|
+
function identity(x) {
|
|
1267
|
+
return x;
|
|
1149
1268
|
}
|
|
1150
1269
|
|
|
1151
1270
|
function ifElseFn(condition, onTrue, onFalse) {
|
|
@@ -1196,21 +1315,10 @@ function indexBy(condition, list) {
|
|
|
1196
1315
|
|
|
1197
1316
|
function indexOf(valueToFind, list) {
|
|
1198
1317
|
if (arguments.length === 1) {
|
|
1199
|
-
return _list =>
|
|
1318
|
+
return _list => _indexOf(valueToFind, _list);
|
|
1200
1319
|
}
|
|
1201
1320
|
|
|
1202
|
-
|
|
1203
|
-
const {
|
|
1204
|
-
length
|
|
1205
|
-
} = list;
|
|
1206
|
-
|
|
1207
|
-
while (++index < length) {
|
|
1208
|
-
if (list[index] === valueToFind) {
|
|
1209
|
-
return index;
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
return -1;
|
|
1321
|
+
return _indexOf(valueToFind, list);
|
|
1214
1322
|
}
|
|
1215
1323
|
|
|
1216
1324
|
function baseSlice(array, start, end) {
|
|
@@ -1304,25 +1412,18 @@ function last(listOrString) {
|
|
|
1304
1412
|
return listOrString[listOrString.length - 1];
|
|
1305
1413
|
}
|
|
1306
1414
|
|
|
1307
|
-
function lastIndexOf(
|
|
1308
|
-
if (arguments.length === 1)
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
while (--index > 0) {
|
|
1312
|
-
if (equals(list[index], target)) {
|
|
1313
|
-
return index;
|
|
1314
|
-
}
|
|
1415
|
+
function lastIndexOf(valueToFind, list) {
|
|
1416
|
+
if (arguments.length === 1) {
|
|
1417
|
+
return _list => _lastIndexOf(valueToFind, _list);
|
|
1315
1418
|
}
|
|
1316
1419
|
|
|
1317
|
-
return
|
|
1420
|
+
return _lastIndexOf(valueToFind, list);
|
|
1318
1421
|
}
|
|
1319
1422
|
|
|
1320
1423
|
function length(x) {
|
|
1321
|
-
if (
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
return x.length;
|
|
1424
|
+
if (_isArray(x)) return x.length;
|
|
1425
|
+
if (typeof x === 'string') return x.length;
|
|
1426
|
+
return NaN;
|
|
1326
1427
|
}
|
|
1327
1428
|
|
|
1328
1429
|
function lens(getter, setter) {
|
|
@@ -1340,8 +1441,9 @@ function nth(index, list) {
|
|
|
1340
1441
|
}
|
|
1341
1442
|
|
|
1342
1443
|
function updateFn(index, newValue, list) {
|
|
1343
|
-
const
|
|
1344
|
-
return
|
|
1444
|
+
const clone = cloneList(list);
|
|
1445
|
+
if (index === -1) return clone.fill(newValue, index);
|
|
1446
|
+
return clone.fill(newValue, index, index + 1);
|
|
1345
1447
|
}
|
|
1346
1448
|
|
|
1347
1449
|
const update = curry(updateFn);
|
|
@@ -1354,12 +1456,6 @@ function lensPath(key) {
|
|
|
1354
1456
|
return lens(path(key), assocPath(key));
|
|
1355
1457
|
}
|
|
1356
1458
|
|
|
1357
|
-
function prop(propToFind, obj) {
|
|
1358
|
-
if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
|
1359
|
-
if (!obj) return undefined;
|
|
1360
|
-
return obj[propToFind];
|
|
1361
|
-
}
|
|
1362
|
-
|
|
1363
1459
|
function lensProp(key) {
|
|
1364
1460
|
return lens(prop(key), assoc(key));
|
|
1365
1461
|
}
|
|
@@ -1459,7 +1555,7 @@ function moveFn(fromIndex, toIndex, list) {
|
|
|
1459
1555
|
}
|
|
1460
1556
|
|
|
1461
1557
|
if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
|
1462
|
-
const clone = list
|
|
1558
|
+
const clone = cloneList(list);
|
|
1463
1559
|
clone[fromIndex] = list[toIndex];
|
|
1464
1560
|
clone[toIndex] = list[fromIndex];
|
|
1465
1561
|
return clone;
|
|
@@ -1583,13 +1679,13 @@ function partitionObject(predicate, iterable) {
|
|
|
1583
1679
|
});
|
|
1584
1680
|
return [yes, no];
|
|
1585
1681
|
}
|
|
1586
|
-
function partitionArray(predicate, list) {
|
|
1682
|
+
function partitionArray(predicate, list, indexed = false) {
|
|
1587
1683
|
const yes = [];
|
|
1588
1684
|
const no = [];
|
|
1589
1685
|
let counter = -1;
|
|
1590
1686
|
|
|
1591
1687
|
while (counter++ < list.length - 1) {
|
|
1592
|
-
if (predicate(list[counter])) {
|
|
1688
|
+
if (indexed ? predicate(list[counter], counter) : predicate(list[counter])) {
|
|
1593
1689
|
yes.push(list[counter]);
|
|
1594
1690
|
} else {
|
|
1595
1691
|
no.push(list[counter]);
|
|
@@ -1613,8 +1709,8 @@ function pathEqFn(pathToSearch, target, input) {
|
|
|
1613
1709
|
|
|
1614
1710
|
const pathEq = curry(pathEqFn);
|
|
1615
1711
|
|
|
1616
|
-
function pathOrFn(defaultValue,
|
|
1617
|
-
return defaultTo(defaultValue, path(
|
|
1712
|
+
function pathOrFn(defaultValue, pathInput, obj) {
|
|
1713
|
+
return defaultTo(defaultValue, path(pathInput, obj));
|
|
1618
1714
|
}
|
|
1619
1715
|
|
|
1620
1716
|
const pathOr = curry(pathOrFn);
|
|
@@ -1802,13 +1898,12 @@ const slice = curry(sliceFn);
|
|
|
1802
1898
|
|
|
1803
1899
|
function sort(sortFn, list) {
|
|
1804
1900
|
if (arguments.length === 1) return _list => sort(sortFn, _list);
|
|
1805
|
-
|
|
1806
|
-
return clone.sort(sortFn);
|
|
1901
|
+
return cloneList(list).sort(sortFn);
|
|
1807
1902
|
}
|
|
1808
1903
|
|
|
1809
1904
|
function sortBy(sortFn, list) {
|
|
1810
1905
|
if (arguments.length === 1) return _list => sortBy(sortFn, _list);
|
|
1811
|
-
const clone = list
|
|
1906
|
+
const clone = cloneList(list);
|
|
1812
1907
|
return clone.sort((a, b) => {
|
|
1813
1908
|
const aSortResult = sortFn(a);
|
|
1814
1909
|
const bSortResult = sortFn(b);
|
|
@@ -1890,9 +1985,22 @@ function splitWhen(predicate, input) {
|
|
|
1890
1985
|
return [preFound, postFound];
|
|
1891
1986
|
}
|
|
1892
1987
|
|
|
1893
|
-
function startsWith(target,
|
|
1894
|
-
if (arguments.length === 1) return
|
|
1895
|
-
|
|
1988
|
+
function startsWith(target, iterable) {
|
|
1989
|
+
if (arguments.length === 1) return _iterable => startsWith(target, _iterable);
|
|
1990
|
+
|
|
1991
|
+
if (typeof iterable === 'string') {
|
|
1992
|
+
return iterable.startsWith(target);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
if (!_isArray(target)) return false;
|
|
1996
|
+
let correct = true;
|
|
1997
|
+
const filtered = target.filter((x, index) => {
|
|
1998
|
+
if (!correct) return false;
|
|
1999
|
+
const result = equals(x, iterable[index]);
|
|
2000
|
+
if (!result) correct = false;
|
|
2001
|
+
return result;
|
|
2002
|
+
});
|
|
2003
|
+
return filtered.length === target.length;
|
|
1896
2004
|
}
|
|
1897
2005
|
|
|
1898
2006
|
function subtract(a, b) {
|
|
@@ -2042,15 +2150,36 @@ function tryCatch(fn, fallback) {
|
|
|
2042
2150
|
};
|
|
2043
2151
|
}
|
|
2044
2152
|
|
|
2153
|
+
function unapply(fn) {
|
|
2154
|
+
return function (...args) {
|
|
2155
|
+
return fn.call(this, args);
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2045
2159
|
function union(x, y) {
|
|
2046
2160
|
if (arguments.length === 1) return _y => union(x, _y);
|
|
2047
|
-
const toReturn = x
|
|
2161
|
+
const toReturn = cloneList(x);
|
|
2048
2162
|
y.forEach(yInstance => {
|
|
2049
2163
|
if (!includes(yInstance, x)) toReturn.push(yInstance);
|
|
2050
2164
|
});
|
|
2051
2165
|
return toReturn;
|
|
2052
2166
|
}
|
|
2053
2167
|
|
|
2168
|
+
function includesWith(predicate, target, list) {
|
|
2169
|
+
let willReturn = false;
|
|
2170
|
+
let index = -1;
|
|
2171
|
+
|
|
2172
|
+
while (++index < list.length && !willReturn) {
|
|
2173
|
+
const value = list[index];
|
|
2174
|
+
|
|
2175
|
+
if (predicate(target, value)) {
|
|
2176
|
+
willReturn = true;
|
|
2177
|
+
}
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
return willReturn;
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2054
2183
|
function uniqWith(predicate, list) {
|
|
2055
2184
|
if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
|
2056
2185
|
let index = -1;
|
|
@@ -2058,9 +2187,8 @@ function uniqWith(predicate, list) {
|
|
|
2058
2187
|
|
|
2059
2188
|
while (++index < list.length) {
|
|
2060
2189
|
const value = list[index];
|
|
2061
|
-
const flag = any(x => predicate(value, x), willReturn);
|
|
2062
2190
|
|
|
2063
|
-
if (!
|
|
2191
|
+
if (!includesWith(predicate, value, willReturn)) {
|
|
2064
2192
|
willReturn.push(value);
|
|
2065
2193
|
}
|
|
2066
2194
|
}
|
|
@@ -2130,7 +2258,7 @@ function without(matchAgainst, source) {
|
|
|
2130
2258
|
return _source => without(matchAgainst, _source);
|
|
2131
2259
|
}
|
|
2132
2260
|
|
|
2133
|
-
return reduce((prev, current) =>
|
|
2261
|
+
return reduce((prev, current) => _indexOf(current, matchAgainst) > -1 ? prev : prev.concat(current), [], source);
|
|
2134
2262
|
}
|
|
2135
2263
|
|
|
2136
2264
|
function xor(a, b) {
|
|
@@ -2164,4 +2292,4 @@ function zipWithFn(fn, x, y) {
|
|
|
2164
2292
|
|
|
2165
2293
|
const zipWith = curry(zipWithFn);
|
|
2166
2294
|
|
|
2167
|
-
export { F, T, add, adjust, all, allPass, always, and, any, anyPass, append, applySpec, assoc, assocPath, both, chain, clamp, clone, complement, compose, concat, cond, converge, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes,
|
|
2295
|
+
export { F, T, _indexOf, _lastIndexOf, add, adjust, all, allPass, always, and, any, anyPass, append, apply, applySpec, assoc, assocPath, bind, both, chain, clamp, clone, complement, compose, concat, cond, converge, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes, indexBy, indexOf, init, intersection, intersperse, is, isEmpty, isNil, join, keys, last, lastIndexOf, length, lens, lensIndex, lensPath, lensProp, map, mapArray, mapObjIndexed, mapObject, match, mathMod, max, maxBy, maxByFn, mean, median, merge, mergeAll, mergeDeepRight, mergeLeft, min, minBy, minByFn, modulo, move, multiply, negate, none, not, nth, objOf, of, omit, once, or, over, partial, partition, partitionArray, partitionObject, path, pathEq, pathOr, paths, pick, pickAll, pipe, pluck, prepend, product, prop, propEq, propIs, propOr, props, range, reduce, reject, repeat, replace, reverse, set, slice, sort, sortBy, split, splitAt, splitEvery, splitWhen, startsWith, subtract, sum, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, times, toLower, toPairs, toString, toUpper, transpose, trim, tryCatch, type, unapply, union, uniq, uniqWith, unless, update, values, view, when, where, whereEq, without, xor, zip, zipObj, zipWith };
|