rambda 6.8.3 → 7.0.2
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 +95 -0
- package/README.md +4157 -4921
- package/dist/rambda.esm.js +336 -209
- package/dist/rambda.js +340 -209
- package/dist/rambda.mjs +336 -209
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +203 -284
- package/index.d.ts +194 -275
- package/package.json +119 -95
- 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 +18 -18
- 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 +17 -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.js
CHANGED
|
@@ -19,10 +19,14 @@ function curry(fn, args = []) {
|
|
|
19
19
|
return (..._args) => (rest => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const cloneList = list => {
|
|
23
|
+
return Array.prototype.slice.call(list);
|
|
24
|
+
};
|
|
25
|
+
|
|
22
26
|
function adjustFn(index, replaceFn, list) {
|
|
23
27
|
const actualIndex = index < 0 ? list.length + index : index;
|
|
24
28
|
if (index >= list.length || actualIndex < 0) return list;
|
|
25
|
-
const clone = list
|
|
29
|
+
const clone = cloneList(list);
|
|
26
30
|
clone[actualIndex] = replaceFn(clone[actualIndex]);
|
|
27
31
|
return clone;
|
|
28
32
|
}
|
|
@@ -40,11 +44,11 @@ function all(predicate, list) {
|
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
function allPass(predicates) {
|
|
43
|
-
return input => {
|
|
47
|
+
return (...input) => {
|
|
44
48
|
let counter = 0;
|
|
45
49
|
|
|
46
50
|
while (counter < predicates.length) {
|
|
47
|
-
if (!predicates[counter](input)) {
|
|
51
|
+
if (!predicates[counter](...input)) {
|
|
48
52
|
return false;
|
|
49
53
|
}
|
|
50
54
|
|
|
@@ -80,11 +84,11 @@ function any(predicate, list) {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
function anyPass(predicates) {
|
|
83
|
-
return input => {
|
|
87
|
+
return (...input) => {
|
|
84
88
|
let counter = 0;
|
|
85
89
|
|
|
86
90
|
while (counter < predicates.length) {
|
|
87
|
-
if (predicates[counter](input)) {
|
|
91
|
+
if (predicates[counter](...input)) {
|
|
88
92
|
return true;
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -98,11 +102,19 @@ function anyPass(predicates) {
|
|
|
98
102
|
function append(x, input) {
|
|
99
103
|
if (arguments.length === 1) return _input => append(x, _input);
|
|
100
104
|
if (typeof input === 'string') return input.split('').concat(x);
|
|
101
|
-
const clone = input
|
|
105
|
+
const clone = cloneList(input);
|
|
102
106
|
clone.push(x);
|
|
103
107
|
return clone;
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
function apply(fn, args) {
|
|
111
|
+
if (arguments.length === 1) {
|
|
112
|
+
return _args => apply(fn, _args);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return fn.apply(this, args);
|
|
116
|
+
}
|
|
117
|
+
|
|
106
118
|
const _isArray = Array.isArray;
|
|
107
119
|
|
|
108
120
|
function __findHighestArity(spec, max = 0) {
|
|
@@ -220,7 +232,7 @@ function assocPathFn(path, newValue, input) {
|
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
if (_isInteger(index) && _isArray(input)) {
|
|
223
|
-
const arr = input
|
|
235
|
+
const arr = cloneList(input);
|
|
224
236
|
arr[index] = newValue;
|
|
225
237
|
return arr;
|
|
226
238
|
}
|
|
@@ -230,87 +242,6 @@ function assocPathFn(path, newValue, input) {
|
|
|
230
242
|
|
|
231
243
|
const assocPath = curry(assocPathFn);
|
|
232
244
|
|
|
233
|
-
function both(f, g) {
|
|
234
|
-
if (arguments.length === 1) return _g => both(f, _g);
|
|
235
|
-
return (...input) => f(...input) && g(...input);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function chain(fn, list) {
|
|
239
|
-
if (arguments.length === 1) {
|
|
240
|
-
return _list => chain(fn, _list);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return [].concat(...list.map(fn));
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function clampFn(min, max, input) {
|
|
247
|
-
if (min > max) {
|
|
248
|
-
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (input >= min && input <= max) return input;
|
|
252
|
-
if (input > max) return max;
|
|
253
|
-
if (input < min) return min;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const clamp = curry(clampFn);
|
|
257
|
-
|
|
258
|
-
function clone(input) {
|
|
259
|
-
const out = _isArray(input) ? Array(input.length) : {};
|
|
260
|
-
if (input && input.getTime) return new Date(input.getTime());
|
|
261
|
-
|
|
262
|
-
for (const key in input) {
|
|
263
|
-
const v = input[key];
|
|
264
|
-
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return out;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function complement(fn) {
|
|
271
|
-
return (...input) => !fn(...input);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function compose(...fns) {
|
|
275
|
-
if (fns.length === 0) {
|
|
276
|
-
throw new Error('compose requires at least one argument');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return (...args) => {
|
|
280
|
-
const list = fns.slice();
|
|
281
|
-
|
|
282
|
-
if (list.length > 0) {
|
|
283
|
-
const fn = list.pop();
|
|
284
|
-
let result = fn(...args);
|
|
285
|
-
|
|
286
|
-
while (list.length > 0) {
|
|
287
|
-
result = list.pop()(result);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return result;
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function concat(x, y) {
|
|
296
|
-
if (arguments.length === 1) return _y => concat(x, _y);
|
|
297
|
-
return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function cond(conditions) {
|
|
301
|
-
return input => {
|
|
302
|
-
let done = false;
|
|
303
|
-
let toReturn;
|
|
304
|
-
conditions.forEach(([predicate, resultClosure]) => {
|
|
305
|
-
if (!done && predicate(input)) {
|
|
306
|
-
done = true;
|
|
307
|
-
toReturn = resultClosure(input);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
return toReturn;
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
|
|
314
245
|
function _curryN(n, cache, fn) {
|
|
315
246
|
return function () {
|
|
316
247
|
let ci = 0;
|
|
@@ -403,6 +334,95 @@ function curryN(n, fn) {
|
|
|
403
334
|
return _arity(n, _curryN(n, [], fn));
|
|
404
335
|
}
|
|
405
336
|
|
|
337
|
+
function bind(fn, thisObj) {
|
|
338
|
+
if (arguments.length === 1) {
|
|
339
|
+
return _thisObj => bind(fn, _thisObj);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return curryN(fn.length, (...args) => fn.apply(thisObj, args));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function both(f, g) {
|
|
346
|
+
if (arguments.length === 1) return _g => both(f, _g);
|
|
347
|
+
return (...input) => f(...input) && g(...input);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function chain(fn, list) {
|
|
351
|
+
if (arguments.length === 1) {
|
|
352
|
+
return _list => chain(fn, _list);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return [].concat(...list.map(fn));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function clampFn(min, max, input) {
|
|
359
|
+
if (min > max) {
|
|
360
|
+
throw new Error('min must not be greater than max in clamp(min, max, value)');
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (input >= min && input <= max) return input;
|
|
364
|
+
if (input > max) return max;
|
|
365
|
+
if (input < min) return min;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const clamp = curry(clampFn);
|
|
369
|
+
|
|
370
|
+
function clone(input) {
|
|
371
|
+
const out = _isArray(input) ? Array(input.length) : {};
|
|
372
|
+
if (input && input.getTime) return new Date(input.getTime());
|
|
373
|
+
|
|
374
|
+
for (const key in input) {
|
|
375
|
+
const v = input[key];
|
|
376
|
+
out[key] = typeof v === 'object' && v !== null ? v.getTime ? new Date(v.getTime()) : clone(v) : v;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return out;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function complement(fn) {
|
|
383
|
+
return (...input) => !fn(...input);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function compose(...fns) {
|
|
387
|
+
if (fns.length === 0) {
|
|
388
|
+
throw new Error('compose requires at least one argument');
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return function (...args) {
|
|
392
|
+
const list = fns.slice();
|
|
393
|
+
|
|
394
|
+
if (list.length > 0) {
|
|
395
|
+
const fn = list.pop();
|
|
396
|
+
let result = fn.apply(this, args);
|
|
397
|
+
|
|
398
|
+
while (list.length > 0) {
|
|
399
|
+
result = list.pop()(result);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return result;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function concat(x, y) {
|
|
408
|
+
if (arguments.length === 1) return _y => concat(x, _y);
|
|
409
|
+
return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function cond(conditions) {
|
|
413
|
+
return input => {
|
|
414
|
+
let done = false;
|
|
415
|
+
let toReturn;
|
|
416
|
+
conditions.forEach(([predicate, resultClosure]) => {
|
|
417
|
+
if (!done && predicate(input)) {
|
|
418
|
+
done = true;
|
|
419
|
+
toReturn = resultClosure(input);
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
return toReturn;
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
406
426
|
const _keys = Object.keys;
|
|
407
427
|
|
|
408
428
|
function mapArray(fn, list, isIndexed = false) {
|
|
@@ -433,11 +453,15 @@ function mapObject(fn, obj) {
|
|
|
433
453
|
return willReturn;
|
|
434
454
|
}
|
|
435
455
|
const mapObjIndexed = mapObject;
|
|
436
|
-
function map(fn,
|
|
437
|
-
if (arguments.length === 1) return
|
|
438
|
-
|
|
439
|
-
if (
|
|
440
|
-
|
|
456
|
+
function map(fn, iterable) {
|
|
457
|
+
if (arguments.length === 1) return _iterable => map(fn, _iterable);
|
|
458
|
+
|
|
459
|
+
if (!iterable) {
|
|
460
|
+
throw new Error('Incorrect iterable input');
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (_isArray(iterable)) return mapArray(fn, iterable);
|
|
464
|
+
return mapObject(fn, iterable);
|
|
441
465
|
}
|
|
442
466
|
|
|
443
467
|
function max(x, y) {
|
|
@@ -486,34 +510,83 @@ function defaultTo(defaultArgument, input) {
|
|
|
486
510
|
}
|
|
487
511
|
|
|
488
512
|
function type(input) {
|
|
489
|
-
const typeOf = typeof input;
|
|
490
|
-
|
|
491
513
|
if (input === null) {
|
|
492
514
|
return 'Null';
|
|
493
515
|
} else if (input === undefined) {
|
|
494
516
|
return 'Undefined';
|
|
495
|
-
} else if (
|
|
496
|
-
return '
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
+
} else if (Number.isNaN(input)) {
|
|
518
|
+
return 'NaN';
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const typeResult = Object.prototype.toString.call(input).slice(8, -1);
|
|
522
|
+
return typeResult === 'AsyncFunction' ? 'Async' : typeResult;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function _lastIndexOf(valueToFind, list) {
|
|
526
|
+
if (!_isArray(list)) {
|
|
527
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const typeOfValue = type(valueToFind);
|
|
531
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.lastIndexOf(valueToFind);
|
|
532
|
+
const {
|
|
533
|
+
length
|
|
534
|
+
} = list;
|
|
535
|
+
let index = length;
|
|
536
|
+
let foundIndex = -1;
|
|
537
|
+
|
|
538
|
+
while (--index > -1 && foundIndex === -1) {
|
|
539
|
+
if (equals(list[index], valueToFind)) {
|
|
540
|
+
foundIndex = index;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return foundIndex;
|
|
545
|
+
}
|
|
546
|
+
function _indexOf(valueToFind, list) {
|
|
547
|
+
if (!_isArray(list)) {
|
|
548
|
+
throw new Error(`Cannot read property 'indexOf' of ${list}`);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const typeOfValue = type(valueToFind);
|
|
552
|
+
if (!['Object', 'Array', 'NaN', 'RegExp'].includes(typeOfValue)) return list.indexOf(valueToFind);
|
|
553
|
+
let index = -1;
|
|
554
|
+
let foundIndex = -1;
|
|
555
|
+
const {
|
|
556
|
+
length
|
|
557
|
+
} = list;
|
|
558
|
+
|
|
559
|
+
while (++index < length && foundIndex === -1) {
|
|
560
|
+
if (equals(list[index], valueToFind)) {
|
|
561
|
+
foundIndex = index;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return foundIndex;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function _arrayFromIterator(iter) {
|
|
569
|
+
const list = [];
|
|
570
|
+
let next;
|
|
571
|
+
|
|
572
|
+
while (!(next = iter.next()).done) {
|
|
573
|
+
list.push(next.value);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
return list;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function _equalsSets(a, b) {
|
|
580
|
+
if (a.size !== b.size) {
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
const aList = _arrayFromIterator(a.values());
|
|
585
|
+
|
|
586
|
+
const bList = _arrayFromIterator(b.values());
|
|
587
|
+
|
|
588
|
+
const filtered = aList.filter(aInstance => _indexOf(aInstance, bList) === -1);
|
|
589
|
+
return filtered.length === 0;
|
|
517
590
|
}
|
|
518
591
|
|
|
519
592
|
function parseError(maybeError) {
|
|
@@ -593,6 +666,10 @@ function equals(a, b) {
|
|
|
593
666
|
return bError[0] ? aError[0] === bError[0] && aError[1] === bError[1] : false;
|
|
594
667
|
}
|
|
595
668
|
|
|
669
|
+
if (aType === 'Set') {
|
|
670
|
+
return _equalsSets(a, b);
|
|
671
|
+
}
|
|
672
|
+
|
|
596
673
|
if (aType === 'Object') {
|
|
597
674
|
const aKeys = Object.keys(a);
|
|
598
675
|
|
|
@@ -617,44 +694,68 @@ function equals(a, b) {
|
|
|
617
694
|
return false;
|
|
618
695
|
}
|
|
619
696
|
|
|
620
|
-
function
|
|
621
|
-
|
|
697
|
+
function includes(valueToFind, iterable) {
|
|
698
|
+
if (arguments.length === 1) return _iterable => includes(valueToFind, _iterable);
|
|
622
699
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
return true;
|
|
626
|
-
}
|
|
700
|
+
if (typeof iterable === 'string') {
|
|
701
|
+
return iterable.includes(valueToFind);
|
|
627
702
|
}
|
|
628
703
|
|
|
629
|
-
|
|
704
|
+
if (!iterable) {
|
|
705
|
+
throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
if (!_isArray(iterable)) return false;
|
|
709
|
+
return _indexOf(valueToFind, iterable) > -1;
|
|
630
710
|
}
|
|
631
|
-
function includes(valueToFind, input) {
|
|
632
|
-
if (arguments.length === 1) return _input => includes(valueToFind, _input);
|
|
633
711
|
|
|
634
|
-
|
|
635
|
-
|
|
712
|
+
class _Set {
|
|
713
|
+
constructor() {
|
|
714
|
+
this.set = new Set();
|
|
715
|
+
this.items = {};
|
|
636
716
|
}
|
|
637
717
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}
|
|
718
|
+
checkUniqueness(item) {
|
|
719
|
+
const type$1 = type(item);
|
|
641
720
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
721
|
+
if (['Null', 'Undefined', 'NaN'].includes(type$1)) {
|
|
722
|
+
if (type$1 in this.items) {
|
|
723
|
+
return false;
|
|
724
|
+
}
|
|
645
725
|
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
726
|
+
this.items[type$1] = true;
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
649
729
|
|
|
650
|
-
|
|
651
|
-
|
|
730
|
+
if (!['Object', 'Array'].includes(type$1)) {
|
|
731
|
+
const prevSize = this.set.size;
|
|
732
|
+
this.set.add(item);
|
|
733
|
+
return this.set.size !== prevSize;
|
|
734
|
+
}
|
|
652
735
|
|
|
653
|
-
if (!
|
|
654
|
-
|
|
736
|
+
if (!(type$1 in this.items)) {
|
|
737
|
+
this.items[type$1] = [item];
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (_indexOf(item, this.items[type$1]) === -1) {
|
|
742
|
+
this.items[type$1].push(item);
|
|
743
|
+
return true;
|
|
655
744
|
}
|
|
745
|
+
|
|
746
|
+
return false;
|
|
656
747
|
}
|
|
657
748
|
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function uniq(list) {
|
|
752
|
+
const set = new _Set();
|
|
753
|
+
const willReturn = [];
|
|
754
|
+
list.forEach(item => {
|
|
755
|
+
if (set.checkUniqueness(item)) {
|
|
756
|
+
willReturn.push(item);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
658
759
|
return willReturn;
|
|
659
760
|
}
|
|
660
761
|
|
|
@@ -805,17 +906,33 @@ function either(firstPredicate, secondPredicate) {
|
|
|
805
906
|
return (...input) => Boolean(firstPredicate(...input) || secondPredicate(...input));
|
|
806
907
|
}
|
|
807
908
|
|
|
808
|
-
function endsWith(target,
|
|
809
|
-
if (arguments.length === 1) return
|
|
810
|
-
return str.endsWith(target);
|
|
811
|
-
}
|
|
909
|
+
function endsWith(target, iterable) {
|
|
910
|
+
if (arguments.length === 1) return _iterable => endsWith(target, _iterable);
|
|
812
911
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
throw new Error('wrong object inputs are passed to R.eqProps');
|
|
912
|
+
if (typeof iterable === 'string') {
|
|
913
|
+
return iterable.endsWith(target);
|
|
816
914
|
}
|
|
817
915
|
|
|
818
|
-
|
|
916
|
+
if (!_isArray(target)) return false;
|
|
917
|
+
const diff = iterable.length - target.length;
|
|
918
|
+
let correct = true;
|
|
919
|
+
const filtered = target.filter((x, index) => {
|
|
920
|
+
if (!correct) return false;
|
|
921
|
+
const result = equals(x, iterable[index + diff]);
|
|
922
|
+
if (!result) correct = false;
|
|
923
|
+
return result;
|
|
924
|
+
});
|
|
925
|
+
return filtered.length === target.length;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function prop(propToFind, obj) {
|
|
929
|
+
if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
|
930
|
+
if (!obj) return undefined;
|
|
931
|
+
return obj[propToFind];
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
function eqPropsFn(property, objA, objB) {
|
|
935
|
+
return equals(prop(property, objA), prop(property, objB));
|
|
819
936
|
}
|
|
820
937
|
|
|
821
938
|
const eqProps = curry(eqPropsFn);
|
|
@@ -904,12 +1021,13 @@ function filterArray(predicate, list, indexed = false) {
|
|
|
904
1021
|
return willReturn;
|
|
905
1022
|
}
|
|
906
1023
|
function filter(predicate, iterable) {
|
|
907
|
-
if (arguments.length === 1)
|
|
908
|
-
|
|
1024
|
+
if (arguments.length === 1) return _iterable => filter(predicate, _iterable);
|
|
1025
|
+
|
|
1026
|
+
if (!iterable) {
|
|
1027
|
+
throw new Error('Incorrect iterable input');
|
|
909
1028
|
}
|
|
910
1029
|
|
|
911
|
-
if (
|
|
912
|
-
if (_isArray(iterable)) return filterArray(predicate, iterable);
|
|
1030
|
+
if (_isArray(iterable)) return filterArray(predicate, iterable, false);
|
|
913
1031
|
return filterObject(predicate, iterable);
|
|
914
1032
|
}
|
|
915
1033
|
|
|
@@ -995,7 +1113,7 @@ function flipFn(fn) {
|
|
|
995
1113
|
return fn(input[1], input[0], input[2], input[3]);
|
|
996
1114
|
}
|
|
997
1115
|
|
|
998
|
-
throw new Error(
|
|
1116
|
+
throw new Error("R.flip doesn't work with arity > 4");
|
|
999
1117
|
};
|
|
1000
1118
|
}
|
|
1001
1119
|
|
|
@@ -1061,7 +1179,7 @@ function groupBy(groupFn, list) {
|
|
|
1061
1179
|
|
|
1062
1180
|
function groupWith(compareFn, list) {
|
|
1063
1181
|
if (!_isArray(list)) throw new TypeError('list.reduce is not a function');
|
|
1064
|
-
const clone = list
|
|
1182
|
+
const clone = cloneList(list);
|
|
1065
1183
|
if (list.length === 1) return [clone];
|
|
1066
1184
|
const toReturn = [];
|
|
1067
1185
|
let holder = [];
|
|
@@ -1122,12 +1240,12 @@ function path(pathInput, obj) {
|
|
|
1122
1240
|
return willReturn;
|
|
1123
1241
|
}
|
|
1124
1242
|
|
|
1125
|
-
function hasPath(
|
|
1243
|
+
function hasPath(pathInput, obj) {
|
|
1126
1244
|
if (arguments.length === 1) {
|
|
1127
|
-
return objHolder => hasPath(
|
|
1245
|
+
return objHolder => hasPath(pathInput, objHolder);
|
|
1128
1246
|
}
|
|
1129
1247
|
|
|
1130
|
-
return path(
|
|
1248
|
+
return path(pathInput, obj) !== undefined;
|
|
1131
1249
|
}
|
|
1132
1250
|
|
|
1133
1251
|
function head(listOrString) {
|
|
@@ -1149,8 +1267,8 @@ function identical(a, b) {
|
|
|
1149
1267
|
return _objectIs$1(a, b);
|
|
1150
1268
|
}
|
|
1151
1269
|
|
|
1152
|
-
function identity(
|
|
1153
|
-
return
|
|
1270
|
+
function identity(x) {
|
|
1271
|
+
return x;
|
|
1154
1272
|
}
|
|
1155
1273
|
|
|
1156
1274
|
function ifElseFn(condition, onTrue, onFalse) {
|
|
@@ -1201,21 +1319,10 @@ function indexBy(condition, list) {
|
|
|
1201
1319
|
|
|
1202
1320
|
function indexOf(valueToFind, list) {
|
|
1203
1321
|
if (arguments.length === 1) {
|
|
1204
|
-
return _list =>
|
|
1322
|
+
return _list => _indexOf(valueToFind, _list);
|
|
1205
1323
|
}
|
|
1206
1324
|
|
|
1207
|
-
|
|
1208
|
-
const {
|
|
1209
|
-
length
|
|
1210
|
-
} = list;
|
|
1211
|
-
|
|
1212
|
-
while (++index < length) {
|
|
1213
|
-
if (list[index] === valueToFind) {
|
|
1214
|
-
return index;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
return -1;
|
|
1325
|
+
return _indexOf(valueToFind, list);
|
|
1219
1326
|
}
|
|
1220
1327
|
|
|
1221
1328
|
function baseSlice(array, start, end) {
|
|
@@ -1309,25 +1416,18 @@ function last(listOrString) {
|
|
|
1309
1416
|
return listOrString[listOrString.length - 1];
|
|
1310
1417
|
}
|
|
1311
1418
|
|
|
1312
|
-
function lastIndexOf(
|
|
1313
|
-
if (arguments.length === 1)
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
while (--index > 0) {
|
|
1317
|
-
if (equals(list[index], target)) {
|
|
1318
|
-
return index;
|
|
1319
|
-
}
|
|
1419
|
+
function lastIndexOf(valueToFind, list) {
|
|
1420
|
+
if (arguments.length === 1) {
|
|
1421
|
+
return _list => _lastIndexOf(valueToFind, _list);
|
|
1320
1422
|
}
|
|
1321
1423
|
|
|
1322
|
-
return
|
|
1424
|
+
return _lastIndexOf(valueToFind, list);
|
|
1323
1425
|
}
|
|
1324
1426
|
|
|
1325
1427
|
function length(x) {
|
|
1326
|
-
if (
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
return x.length;
|
|
1428
|
+
if (_isArray(x)) return x.length;
|
|
1429
|
+
if (typeof x === 'string') return x.length;
|
|
1430
|
+
return NaN;
|
|
1331
1431
|
}
|
|
1332
1432
|
|
|
1333
1433
|
function lens(getter, setter) {
|
|
@@ -1345,8 +1445,9 @@ function nth(index, list) {
|
|
|
1345
1445
|
}
|
|
1346
1446
|
|
|
1347
1447
|
function updateFn(index, newValue, list) {
|
|
1348
|
-
const
|
|
1349
|
-
return
|
|
1448
|
+
const clone = cloneList(list);
|
|
1449
|
+
if (index === -1) return clone.fill(newValue, index);
|
|
1450
|
+
return clone.fill(newValue, index, index + 1);
|
|
1350
1451
|
}
|
|
1351
1452
|
|
|
1352
1453
|
const update = curry(updateFn);
|
|
@@ -1359,12 +1460,6 @@ function lensPath(key) {
|
|
|
1359
1460
|
return lens(path(key), assocPath(key));
|
|
1360
1461
|
}
|
|
1361
1462
|
|
|
1362
|
-
function prop(propToFind, obj) {
|
|
1363
|
-
if (arguments.length === 1) return _obj => prop(propToFind, _obj);
|
|
1364
|
-
if (!obj) return undefined;
|
|
1365
|
-
return obj[propToFind];
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
1463
|
function lensProp(key) {
|
|
1369
1464
|
return lens(prop(key), assoc(key));
|
|
1370
1465
|
}
|
|
@@ -1464,7 +1559,7 @@ function moveFn(fromIndex, toIndex, list) {
|
|
|
1464
1559
|
}
|
|
1465
1560
|
|
|
1466
1561
|
if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list;
|
|
1467
|
-
const clone = list
|
|
1562
|
+
const clone = cloneList(list);
|
|
1468
1563
|
clone[fromIndex] = list[toIndex];
|
|
1469
1564
|
clone[toIndex] = list[fromIndex];
|
|
1470
1565
|
return clone;
|
|
@@ -1618,8 +1713,8 @@ function pathEqFn(pathToSearch, target, input) {
|
|
|
1618
1713
|
|
|
1619
1714
|
const pathEq = curry(pathEqFn);
|
|
1620
1715
|
|
|
1621
|
-
function pathOrFn(defaultValue,
|
|
1622
|
-
return defaultTo(defaultValue, path(
|
|
1716
|
+
function pathOrFn(defaultValue, pathInput, obj) {
|
|
1717
|
+
return defaultTo(defaultValue, path(pathInput, obj));
|
|
1623
1718
|
}
|
|
1624
1719
|
|
|
1625
1720
|
const pathOr = curry(pathOrFn);
|
|
@@ -1807,13 +1902,12 @@ const slice = curry(sliceFn);
|
|
|
1807
1902
|
|
|
1808
1903
|
function sort(sortFn, list) {
|
|
1809
1904
|
if (arguments.length === 1) return _list => sort(sortFn, _list);
|
|
1810
|
-
|
|
1811
|
-
return clone.sort(sortFn);
|
|
1905
|
+
return cloneList(list).sort(sortFn);
|
|
1812
1906
|
}
|
|
1813
1907
|
|
|
1814
1908
|
function sortBy(sortFn, list) {
|
|
1815
1909
|
if (arguments.length === 1) return _list => sortBy(sortFn, _list);
|
|
1816
|
-
const clone = list
|
|
1910
|
+
const clone = cloneList(list);
|
|
1817
1911
|
return clone.sort((a, b) => {
|
|
1818
1912
|
const aSortResult = sortFn(a);
|
|
1819
1913
|
const bSortResult = sortFn(b);
|
|
@@ -1895,9 +1989,22 @@ function splitWhen(predicate, input) {
|
|
|
1895
1989
|
return [preFound, postFound];
|
|
1896
1990
|
}
|
|
1897
1991
|
|
|
1898
|
-
function startsWith(target,
|
|
1899
|
-
if (arguments.length === 1) return
|
|
1900
|
-
|
|
1992
|
+
function startsWith(target, iterable) {
|
|
1993
|
+
if (arguments.length === 1) return _iterable => startsWith(target, _iterable);
|
|
1994
|
+
|
|
1995
|
+
if (typeof iterable === 'string') {
|
|
1996
|
+
return iterable.startsWith(target);
|
|
1997
|
+
}
|
|
1998
|
+
|
|
1999
|
+
if (!_isArray(target)) return false;
|
|
2000
|
+
let correct = true;
|
|
2001
|
+
const filtered = target.filter((x, index) => {
|
|
2002
|
+
if (!correct) return false;
|
|
2003
|
+
const result = equals(x, iterable[index]);
|
|
2004
|
+
if (!result) correct = false;
|
|
2005
|
+
return result;
|
|
2006
|
+
});
|
|
2007
|
+
return filtered.length === target.length;
|
|
1901
2008
|
}
|
|
1902
2009
|
|
|
1903
2010
|
function subtract(a, b) {
|
|
@@ -2047,15 +2154,36 @@ function tryCatch(fn, fallback) {
|
|
|
2047
2154
|
};
|
|
2048
2155
|
}
|
|
2049
2156
|
|
|
2157
|
+
function unapply(fn) {
|
|
2158
|
+
return function (...args) {
|
|
2159
|
+
return fn.call(this, args);
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2050
2163
|
function union(x, y) {
|
|
2051
2164
|
if (arguments.length === 1) return _y => union(x, _y);
|
|
2052
|
-
const toReturn = x
|
|
2165
|
+
const toReturn = cloneList(x);
|
|
2053
2166
|
y.forEach(yInstance => {
|
|
2054
2167
|
if (!includes(yInstance, x)) toReturn.push(yInstance);
|
|
2055
2168
|
});
|
|
2056
2169
|
return toReturn;
|
|
2057
2170
|
}
|
|
2058
2171
|
|
|
2172
|
+
function includesWith(predicate, target, list) {
|
|
2173
|
+
let willReturn = false;
|
|
2174
|
+
let index = -1;
|
|
2175
|
+
|
|
2176
|
+
while (++index < list.length && !willReturn) {
|
|
2177
|
+
const value = list[index];
|
|
2178
|
+
|
|
2179
|
+
if (predicate(target, value)) {
|
|
2180
|
+
willReturn = true;
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
return willReturn;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2059
2187
|
function uniqWith(predicate, list) {
|
|
2060
2188
|
if (arguments.length === 1) return _list => uniqWith(predicate, _list);
|
|
2061
2189
|
let index = -1;
|
|
@@ -2063,9 +2191,8 @@ function uniqWith(predicate, list) {
|
|
|
2063
2191
|
|
|
2064
2192
|
while (++index < list.length) {
|
|
2065
2193
|
const value = list[index];
|
|
2066
|
-
const flag = any(x => predicate(value, x), willReturn);
|
|
2067
2194
|
|
|
2068
|
-
if (!
|
|
2195
|
+
if (!includesWith(predicate, value, willReturn)) {
|
|
2069
2196
|
willReturn.push(value);
|
|
2070
2197
|
}
|
|
2071
2198
|
}
|
|
@@ -2135,7 +2262,7 @@ function without(matchAgainst, source) {
|
|
|
2135
2262
|
return _source => without(matchAgainst, _source);
|
|
2136
2263
|
}
|
|
2137
2264
|
|
|
2138
|
-
return reduce((prev, current) =>
|
|
2265
|
+
return reduce((prev, current) => _indexOf(current, matchAgainst) > -1 ? prev : prev.concat(current), [], source);
|
|
2139
2266
|
}
|
|
2140
2267
|
|
|
2141
2268
|
function xor(a, b) {
|
|
@@ -2171,6 +2298,8 @@ const zipWith = curry(zipWithFn);
|
|
|
2171
2298
|
|
|
2172
2299
|
exports.F = F;
|
|
2173
2300
|
exports.T = T;
|
|
2301
|
+
exports._indexOf = _indexOf;
|
|
2302
|
+
exports._lastIndexOf = _lastIndexOf;
|
|
2174
2303
|
exports.add = add;
|
|
2175
2304
|
exports.adjust = adjust;
|
|
2176
2305
|
exports.all = all;
|
|
@@ -2180,9 +2309,11 @@ exports.and = and;
|
|
|
2180
2309
|
exports.any = any;
|
|
2181
2310
|
exports.anyPass = anyPass;
|
|
2182
2311
|
exports.append = append;
|
|
2312
|
+
exports.apply = apply;
|
|
2183
2313
|
exports.applySpec = applySpec;
|
|
2184
2314
|
exports.assoc = assoc;
|
|
2185
2315
|
exports.assocPath = assocPath;
|
|
2316
|
+
exports.bind = bind;
|
|
2186
2317
|
exports.both = both;
|
|
2187
2318
|
exports.chain = chain;
|
|
2188
2319
|
exports.clamp = clamp;
|
|
@@ -2233,7 +2364,6 @@ exports.identity = identity;
|
|
|
2233
2364
|
exports.ifElse = ifElse;
|
|
2234
2365
|
exports.inc = inc;
|
|
2235
2366
|
exports.includes = includes;
|
|
2236
|
-
exports.includesArray = includesArray;
|
|
2237
2367
|
exports.indexBy = indexBy;
|
|
2238
2368
|
exports.indexOf = indexOf;
|
|
2239
2369
|
exports.init = init;
|
|
@@ -2335,6 +2465,7 @@ exports.transpose = transpose;
|
|
|
2335
2465
|
exports.trim = trim;
|
|
2336
2466
|
exports.tryCatch = tryCatch;
|
|
2337
2467
|
exports.type = type;
|
|
2468
|
+
exports.unapply = unapply;
|
|
2338
2469
|
exports.union = union;
|
|
2339
2470
|
exports.uniq = uniq;
|
|
2340
2471
|
exports.uniqWith = uniqWith;
|