rambda 8.1.0 → 8.3.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/dist/rambda.js CHANGED
@@ -13,6 +13,121 @@ function add(a, b) {
13
13
  return Number(a) + Number(b);
14
14
  }
15
15
 
16
+ function _concat(set1, set2) {
17
+ set1 = set1 || [];
18
+ set2 = set2 || [];
19
+ let idx;
20
+ const len1 = set1.length;
21
+ const len2 = set2.length;
22
+ const result = [];
23
+ idx = 0;
24
+ while (idx < len1) {
25
+ result[result.length] = set1[idx];
26
+ idx += 1;
27
+ }
28
+ idx = 0;
29
+ while (idx < len2) {
30
+ result[result.length] = set2[idx];
31
+ idx += 1;
32
+ }
33
+ return result;
34
+ }
35
+
36
+ function _arity(n, fn) {
37
+ switch (n) {
38
+ case 0:
39
+ return function () {
40
+ return fn.apply(this, arguments);
41
+ };
42
+ case 1:
43
+ return function (_1) {
44
+ return fn.apply(this, arguments);
45
+ };
46
+ case 2:
47
+ return function (_1, _2) {
48
+ return fn.apply(this, arguments);
49
+ };
50
+ case 3:
51
+ return function (_1, _2, _3) {
52
+ return fn.apply(this, arguments);
53
+ };
54
+ case 4:
55
+ return function (_1, _2, _3, _4) {
56
+ return fn.apply(this, arguments);
57
+ };
58
+ case 5:
59
+ return function (_1, _2, _3, _4, _5) {
60
+ return fn.apply(this, arguments);
61
+ };
62
+ case 6:
63
+ return function (_1, _2, _3, _4, _5, _6) {
64
+ return fn.apply(this, arguments);
65
+ };
66
+ case 7:
67
+ return function (_1, _2, _3, _4, _5, _6, _7) {
68
+ return fn.apply(this, arguments);
69
+ };
70
+ case 8:
71
+ return function (_1, _2, _3, _4, _5, _6, _7, _8) {
72
+ return fn.apply(this, arguments);
73
+ };
74
+ case 9:
75
+ return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
76
+ return fn.apply(this, arguments);
77
+ };
78
+ default:
79
+ return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
80
+ return fn.apply(this, arguments);
81
+ };
82
+ }
83
+ }
84
+
85
+ function _curryN(n, cache, fn) {
86
+ return function () {
87
+ let ci = 0;
88
+ let ai = 0;
89
+ const cl = cache.length;
90
+ const al = arguments.length;
91
+ const args = new Array(cl + al);
92
+ while (ci < cl) {
93
+ args[ci] = cache[ci];
94
+ ci++;
95
+ }
96
+ while (ai < al) {
97
+ args[cl + ai] = arguments[ai];
98
+ ai++;
99
+ }
100
+ const remaining = n - args.length;
101
+ return args.length >= n ? fn.apply(this, args) : _arity(remaining, _curryN(n, args, fn));
102
+ };
103
+ }
104
+ function curryN(n, fn) {
105
+ if (arguments.length === 1) return _fn => curryN(n, _fn);
106
+ if (n > 10) {
107
+ throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
108
+ }
109
+ return _arity(n, _curryN(n, [], fn));
110
+ }
111
+
112
+ function addIndex(originalFunction, initialIndexFn = () => 0, loopIndexChange = x => x + 1) {
113
+ return curryN(originalFunction.length, function () {
114
+ const origFn = arguments[0];
115
+ const list = arguments[arguments.length - 1];
116
+ let idx = initialIndexFn(list.length);
117
+ const args = Array.prototype.slice.call(arguments, 0);
118
+ args[0] = function () {
119
+ const result = origFn.apply(this, _concat(arguments, [idx, list]));
120
+ idx = loopIndexChange(idx);
121
+ return result;
122
+ };
123
+ return originalFunction.apply(this, args);
124
+ });
125
+ }
126
+
127
+ function addIndexRight(originalFunction) {
128
+ return addIndex(originalFunction, listLength => listLength - 1, x => x - 1);
129
+ }
130
+
16
131
  const cloneList = list => Array.prototype.slice.call(list);
17
132
 
18
133
  function curry(fn, args = []) {
@@ -83,6 +198,28 @@ function anyPass(predicates) {
83
198
  };
84
199
  }
85
200
 
201
+ function ap(functions, input) {
202
+ if (arguments.length === 1) {
203
+ return _inputs => ap(functions, _inputs);
204
+ }
205
+ return functions.reduce((acc, fn) => [...acc, ...input.map(fn)], []);
206
+ }
207
+
208
+ function aperture(step, list) {
209
+ if (arguments.length === 1) {
210
+ return _list => aperture(step, _list);
211
+ }
212
+ if (step > list.length) return [];
213
+ let idx = 0;
214
+ const limit = list.length - (step - 1);
215
+ const acc = new Array(limit);
216
+ while (idx < limit) {
217
+ acc[idx] = list.slice(idx, idx + step);
218
+ idx += 1;
219
+ }
220
+ return acc;
221
+ }
222
+
86
223
  function append(x, input) {
87
224
  if (arguments.length === 1) return _input => append(x, _input);
88
225
  if (typeof input === 'string') return input.split('').concat(x);
@@ -168,6 +305,26 @@ function applySpec(spec, ...args) {
168
305
  return toReturn;
169
306
  }
170
307
 
308
+ function applyTo(input, fn) {
309
+ if (arguments.length === 1) {
310
+ return _fn => applyTo(input, _fn);
311
+ }
312
+ return fn(input);
313
+ }
314
+
315
+ function createCompareFunction(a, b, winner, loser) {
316
+ if (a === b) return 0;
317
+ return a < b ? winner : loser;
318
+ }
319
+ function ascend(getFunction, a, b) {
320
+ if (arguments.length === 1) {
321
+ return (_a, _b) => ascend(getFunction, _a, _b);
322
+ }
323
+ const aValue = getFunction(a);
324
+ const bValue = getFunction(b);
325
+ return createCompareFunction(aValue, bValue, -1, 1);
326
+ }
327
+
171
328
  function assocFn(prop, newValue, obj) {
172
329
  return Object.assign({}, obj, {
173
330
  [prop]: newValue
@@ -200,79 +357,9 @@ function assocPathFn(path, newValue, input) {
200
357
  }
201
358
  const assocPath = curry(assocPathFn);
202
359
 
203
- function _curryN(n, cache, fn) {
204
- return function () {
205
- let ci = 0;
206
- let ai = 0;
207
- const cl = cache.length;
208
- const al = arguments.length;
209
- const args = new Array(cl + al);
210
- while (ci < cl) {
211
- args[ci] = cache[ci];
212
- ci++;
213
- }
214
- while (ai < al) {
215
- args[cl + ai] = arguments[ai];
216
- ai++;
217
- }
218
- const remaining = n - args.length;
219
- return args.length >= n ? fn.apply(this, args) : _arity$1(remaining, _curryN(n, args, fn));
220
- };
221
- }
222
- function _arity$1(n, fn) {
223
- switch (n) {
224
- case 0:
225
- return function () {
226
- return fn.apply(this, arguments);
227
- };
228
- case 1:
229
- return function (_1) {
230
- return fn.apply(this, arguments);
231
- };
232
- case 2:
233
- return function (_1, _2) {
234
- return fn.apply(this, arguments);
235
- };
236
- case 3:
237
- return function (_1, _2, _3) {
238
- return fn.apply(this, arguments);
239
- };
240
- case 4:
241
- return function (_1, _2, _3, _4) {
242
- return fn.apply(this, arguments);
243
- };
244
- case 5:
245
- return function (_1, _2, _3, _4, _5) {
246
- return fn.apply(this, arguments);
247
- };
248
- case 6:
249
- return function (_1, _2, _3, _4, _5, _6) {
250
- return fn.apply(this, arguments);
251
- };
252
- case 7:
253
- return function (_1, _2, _3, _4, _5, _6, _7) {
254
- return fn.apply(this, arguments);
255
- };
256
- case 8:
257
- return function (_1, _2, _3, _4, _5, _6, _7, _8) {
258
- return fn.apply(this, arguments);
259
- };
260
- case 9:
261
- return function (_1, _2, _3, _4, _5, _6, _7, _8, _9) {
262
- return fn.apply(this, arguments);
263
- };
264
- default:
265
- return function (_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) {
266
- return fn.apply(this, arguments);
267
- };
268
- }
269
- }
270
- function curryN(n, fn) {
271
- if (arguments.length === 1) return _fn => curryN(n, _fn);
272
- if (n > 10) {
273
- throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
274
- }
275
- return _arity$1(n, _curryN(n, [], fn));
360
+ function binary(fn) {
361
+ if (fn.length <= 2) return fn;
362
+ return (a, b) => fn(a, b);
276
363
  }
277
364
 
278
365
  function bind(fn, thisObj) {
@@ -287,6 +374,8 @@ function both(f, g) {
287
374
  return (...input) => f(...input) && g(...input);
288
375
  }
289
376
 
377
+ const call = (fn, ...inputs) => fn(...inputs);
378
+
290
379
  function chain(fn, list) {
291
380
  if (arguments.length === 1) {
292
381
  return _list => chain(fn, _list);
@@ -314,10 +403,6 @@ function clone(input) {
314
403
  return out;
315
404
  }
316
405
 
317
- function complement(fn) {
318
- return (...input) => !fn(...input);
319
- }
320
-
321
406
  class ReduceStopper {
322
407
  constructor(value) {
323
408
  this.value = value;
@@ -344,56 +429,35 @@ function reduceFn(reducer, acc, list) {
344
429
  const reduce = curry(reduceFn);
345
430
  const reduceStopper = value => new ReduceStopper(value);
346
431
 
347
- function _arity(n, fn) {
348
- switch (n) {
349
- case 0:
350
- return function () {
351
- return fn.apply(this, arguments);
352
- };
353
- case 1:
354
- return function (a0) {
355
- return fn.apply(this, arguments);
356
- };
357
- case 2:
358
- return function (a0, a1) {
359
- return fn.apply(this, arguments);
360
- };
361
- case 3:
362
- return function (a0, a1, a2) {
363
- return fn.apply(this, arguments);
364
- };
365
- case 4:
366
- return function (a0, a1, a2, a3) {
367
- return fn.apply(this, arguments);
368
- };
369
- case 5:
370
- return function (a0, a1, a2, a3, a4) {
371
- return fn.apply(this, arguments);
372
- };
373
- case 6:
374
- return function (a0, a1, a2, a3, a4, a5) {
375
- return fn.apply(this, arguments);
376
- };
377
- case 7:
378
- return function (a0, a1, a2, a3, a4, a5, a6) {
379
- return fn.apply(this, arguments);
380
- };
381
- case 8:
382
- return function (a0, a1, a2, a3, a4, a5, a6, a7) {
383
- return fn.apply(this, arguments);
384
- };
385
- case 9:
386
- return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) {
387
- return fn.apply(this, arguments);
388
- };
389
- case 10:
390
- return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
391
- return fn.apply(this, arguments);
392
- };
393
- default:
394
- throw new Error('First argument to _arity must be a non-negative integer no greater than ten');
432
+ function collectBy(fn, list) {
433
+ if (arguments.length === 1) {
434
+ return _list => collectBy(fn, _list);
435
+ }
436
+ const group = reduce((o, x) => {
437
+ const tag = fn(x);
438
+ if (o[tag] === undefined) {
439
+ o[tag] = [];
440
+ }
441
+ o[tag].push(x);
442
+ return o;
443
+ }, {}, list);
444
+ const newList = [];
445
+ for (const tag in group) {
446
+ newList.push(group[tag]);
395
447
  }
448
+ return newList;
449
+ }
450
+
451
+ function comparator(fn) {
452
+ return function (a, b) {
453
+ return fn(a, b) ? -1 : fn(b, a) ? 1 : 0;
454
+ };
455
+ }
456
+
457
+ function complement(fn) {
458
+ return (...input) => !fn(...input);
396
459
  }
460
+
397
461
  function _pipe(f, g) {
398
462
  return function () {
399
463
  return g.call(this, f.apply(this, arguments));
@@ -413,6 +477,49 @@ function compose() {
413
477
  return pipe.apply(this, Array.prototype.slice.call(arguments, 0).reverse());
414
478
  }
415
479
 
480
+ function head(listOrString) {
481
+ if (typeof listOrString === 'string') return listOrString[0] || '';
482
+ return listOrString[0];
483
+ }
484
+
485
+ function identity(x) {
486
+ return x;
487
+ }
488
+
489
+ function reverse(listOrString) {
490
+ if (typeof listOrString === 'string') {
491
+ return listOrString.split('').reverse().join('');
492
+ }
493
+ const clone = listOrString.slice();
494
+ return clone.reverse();
495
+ }
496
+
497
+ function drop(howManyToDrop, listOrString) {
498
+ if (arguments.length === 1) return _list => drop(howManyToDrop, _list);
499
+ return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0);
500
+ }
501
+
502
+ function tail(listOrString) {
503
+ return drop(1, listOrString);
504
+ }
505
+
506
+ function pipeWith(xf, list) {
507
+ if (list.length <= 0) {
508
+ return identity;
509
+ }
510
+ const headList = head(list);
511
+ const tailList = tail(list);
512
+ return _arity(headList.length, function () {
513
+ return reduce(function (result, f) {
514
+ return xf.call(this, f, result);
515
+ }, headList.apply(this, arguments), tailList);
516
+ });
517
+ }
518
+ function composeWith(xf, list) {
519
+ if (arguments.length === 1) return _list => composeWith(xf, _list);
520
+ return pipeWith.apply(this, [xf, reverse(list)]);
521
+ }
522
+
416
523
  function concat(x, y) {
417
524
  if (arguments.length === 1) return _y => concat(x, _y);
418
525
  return typeof x === 'string' ? `${x}${y}` : [...x, ...y];
@@ -521,6 +628,15 @@ function defaultTo(defaultArgument, input) {
521
628
  return isFalsy(input) ? defaultArgument : input;
522
629
  }
523
630
 
631
+ function descend(getFunction, a, b) {
632
+ if (arguments.length === 1) {
633
+ return (_a, _b) => descend(getFunction, _a, _b);
634
+ }
635
+ const aValue = getFunction(a);
636
+ const bValue = getFunction(b);
637
+ return createCompareFunction(aValue, bValue, 1, -1);
638
+ }
639
+
524
640
  function type(input) {
525
641
  if (input === null) {
526
642
  return 'Null';
@@ -756,11 +872,6 @@ function divide(a, b) {
756
872
  return a / b;
757
873
  }
758
874
 
759
- function drop(howManyToDrop, listOrString) {
760
- if (arguments.length === 1) return _list => drop(howManyToDrop, _list);
761
- return listOrString.slice(howManyToDrop > 0 ? howManyToDrop : 0);
762
- }
763
-
764
875
  function dropLast(howManyToDrop, listOrString) {
765
876
  if (arguments.length === 1) {
766
877
  return _listOrString => dropLast(howManyToDrop, _listOrString);
@@ -1154,11 +1265,6 @@ function hasPath(pathInput, obj) {
1154
1265
  return path(pathInput, obj) !== undefined;
1155
1266
  }
1156
1267
 
1157
- function head(listOrString) {
1158
- if (typeof listOrString === 'string') return listOrString[0] || '';
1159
- return listOrString[0];
1160
- }
1161
-
1162
1268
  function _objectIs(a, b) {
1163
1269
  if (a === b) {
1164
1270
  return a !== 0 || 1 / a === 1 / b;
@@ -1172,10 +1278,6 @@ function identical(a, b) {
1172
1278
  return objectIs(a, b);
1173
1279
  }
1174
1280
 
1175
- function identity(x) {
1176
- return x;
1177
- }
1178
-
1179
1281
  function ifElseFn(condition, onTrue, onFalse) {
1180
1282
  return (...input) => {
1181
1283
  const conditionResult = typeof condition === 'boolean' ? condition : condition(...input);
@@ -1828,14 +1930,6 @@ function replaceFn(pattern, replacer, str) {
1828
1930
  }
1829
1931
  const replace = curry(replaceFn);
1830
1932
 
1831
- function reverse(listOrString) {
1832
- if (typeof listOrString === 'string') {
1833
- return listOrString.split('').reverse().join('');
1834
- }
1835
- const clone = listOrString.slice();
1836
- return clone.reverse();
1837
- }
1838
-
1839
1933
  function setFn(lens, replacer, x) {
1840
1934
  return over(lens, always(replacer), x);
1841
1935
  }
@@ -1955,10 +2049,6 @@ function symmetricDifference(x, y) {
1955
2049
  return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
1956
2050
  }
1957
2051
 
1958
- function tail(listOrString) {
1959
- return drop(1, listOrString);
1960
- }
1961
-
1962
2052
  function takeLast(howMany, listOrString) {
1963
2053
  if (arguments.length === 1) return _listOrString => takeLast(howMany, _listOrString);
1964
2054
  const len = listOrString.length;
@@ -2236,11 +2326,12 @@ const zipWith = curry(zipWithFn);
2236
2326
  exports.F = F;
2237
2327
  exports.T = T;
2238
2328
  exports.__findHighestArity = __findHighestArity;
2239
- exports._arity = _arity;
2240
2329
  exports._indexOf = _indexOf;
2241
2330
  exports._lastIndexOf = _lastIndexOf;
2242
2331
  exports._pipe = _pipe;
2243
2332
  exports.add = add;
2333
+ exports.addIndex = addIndex;
2334
+ exports.addIndexRight = addIndexRight;
2244
2335
  exports.adjust = adjust;
2245
2336
  exports.all = all;
2246
2337
  exports.allPass = allPass;
@@ -2248,27 +2339,38 @@ exports.always = always;
2248
2339
  exports.and = and;
2249
2340
  exports.any = any;
2250
2341
  exports.anyPass = anyPass;
2342
+ exports.ap = ap;
2343
+ exports.aperture = aperture;
2251
2344
  exports.append = append;
2252
2345
  exports.apply = apply;
2253
2346
  exports.applySpec = applySpec;
2347
+ exports.applyTo = applyTo;
2348
+ exports.ascend = ascend;
2254
2349
  exports.assoc = assoc;
2255
2350
  exports.assocPath = assocPath;
2351
+ exports.binary = binary;
2256
2352
  exports.bind = bind;
2257
2353
  exports.both = both;
2354
+ exports.call = call;
2258
2355
  exports.chain = chain;
2259
2356
  exports.clamp = clamp;
2260
2357
  exports.clone = clone;
2358
+ exports.collectBy = collectBy;
2359
+ exports.comparator = comparator;
2261
2360
  exports.complement = complement;
2262
2361
  exports.compose = compose;
2362
+ exports.composeWith = composeWith;
2263
2363
  exports.concat = concat;
2264
2364
  exports.cond = cond;
2265
2365
  exports.converge = converge;
2266
2366
  exports.count = count;
2267
2367
  exports.countBy = countBy;
2368
+ exports.createCompareFunction = createCompareFunction;
2268
2369
  exports.curry = curry;
2269
2370
  exports.curryN = curryN;
2270
2371
  exports.dec = dec;
2271
2372
  exports.defaultTo = defaultTo;
2373
+ exports.descend = descend;
2272
2374
  exports.difference = difference;
2273
2375
  exports.differenceWith = differenceWith;
2274
2376
  exports.differenceWithFn = differenceWithFn;
@@ -2376,6 +2478,7 @@ exports.paths = paths;
2376
2478
  exports.pick = pick;
2377
2479
  exports.pickAll = pickAll;
2378
2480
  exports.pipe = pipe;
2481
+ exports.pipeWith = pipeWith;
2379
2482
  exports.pluck = pluck;
2380
2483
  exports.prepend = prepend;
2381
2484
  exports.product = product;