rambda 10.3.4 → 11.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/dist/rambda.cjs CHANGED
@@ -258,60 +258,6 @@ function descend(getFunction) {
258
258
  }
259
259
  }
260
260
 
261
- function drop(howManyToDrop, ) {
262
- return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
263
- }
264
-
265
- function dropLast(numberItems) {
266
- return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
267
- }
268
-
269
- function dropLastWhile(predicate) {
270
- return list => {
271
- if (list.length === 0) {
272
- return list
273
- }
274
-
275
- const toReturn = [];
276
- let counter = list.length;
277
-
278
- while (counter) {
279
- const item = list[--counter];
280
- if (!predicate(item, counter)) {
281
- toReturn.push(item);
282
- break
283
- }
284
- }
285
-
286
- while (counter) {
287
- toReturn.push(list[--counter]);
288
- }
289
-
290
- return toReturn.reverse()
291
- }
292
- }
293
-
294
- function dropWhile(predicate) {
295
- return iterable => {
296
- const toReturn = [];
297
- let counter = 0;
298
-
299
- while (counter < iterable.length) {
300
- const item = iterable[counter++];
301
- if (!predicate(item, counter)) {
302
- toReturn.push(item);
303
- break
304
- }
305
- }
306
-
307
- while (counter < iterable.length) {
308
- toReturn.push(iterable[counter++]);
309
- }
310
-
311
- return toReturn
312
- }
313
- }
314
-
315
261
  function type(input) {
316
262
  if (input === null) {
317
263
  return 'Null'
@@ -535,6 +481,83 @@ function equals(a) {
535
481
  return b => equalsFn(a, b)
536
482
  }
537
483
 
484
+ function includes(valueToFind) {
485
+ return iterable => {
486
+ if (typeof iterable === 'string') {
487
+ return iterable.includes(valueToFind)
488
+ }
489
+ if (!iterable) {
490
+ throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
491
+ }
492
+ if (!isArray(iterable)) {
493
+ return false
494
+ }
495
+
496
+ return _indexOf(valueToFind, iterable) > -1
497
+ }
498
+ }
499
+
500
+ function difference(x) {
501
+ return y => ([
502
+ ...filter(value => !includes(value)(y))(x),
503
+ ...filter(value => !includes(value)(x))(y),
504
+ ])
505
+ }
506
+
507
+ function drop(howManyToDrop, ) {
508
+ return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
509
+ }
510
+
511
+ function dropLast(numberItems) {
512
+ return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
513
+ }
514
+
515
+ function dropLastWhile(predicate) {
516
+ return list => {
517
+ if (list.length === 0) {
518
+ return list
519
+ }
520
+
521
+ const toReturn = [];
522
+ let counter = list.length;
523
+
524
+ while (counter) {
525
+ const item = list[--counter];
526
+ if (!predicate(item, counter)) {
527
+ toReturn.push(item);
528
+ break
529
+ }
530
+ }
531
+
532
+ while (counter) {
533
+ toReturn.push(list[--counter]);
534
+ }
535
+
536
+ return toReturn.reverse()
537
+ }
538
+ }
539
+
540
+ function dropWhile(predicate) {
541
+ return iterable => {
542
+ const toReturn = [];
543
+ let counter = 0;
544
+
545
+ while (counter < iterable.length) {
546
+ const item = iterable[counter++];
547
+ if (!predicate(item, counter)) {
548
+ toReturn.push(item);
549
+ break
550
+ }
551
+ }
552
+
553
+ while (counter < iterable.length) {
554
+ toReturn.push(iterable[counter++]);
555
+ }
556
+
557
+ return toReturn
558
+ }
559
+ }
560
+
538
561
  class _Set {
539
562
  constructor() {
540
563
  this.set = new Set();
@@ -613,24 +636,30 @@ function evolve(rules) {
613
636
  return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
614
637
  }
615
638
 
616
- function includes(valueToFind) {
617
- return iterable => {
618
- if (typeof iterable === 'string') {
619
- return iterable.includes(valueToFind)
620
- }
621
- if (!iterable) {
622
- throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
623
- }
624
- if (!isArray(iterable)) {
625
- return false
626
- }
639
+ function excludes(valueToFind) {
640
+ return iterable => !includes(valueToFind)(iterable)
641
+ }
627
642
 
628
- return _indexOf(valueToFind, iterable) > -1
643
+ function find(predicate) {
644
+ return list => {
645
+ let index = 0;
646
+ const len = list.length;
647
+
648
+ while (index < len) {
649
+ const x = list[index];
650
+ if (predicate(x)) {
651
+ return x
652
+ }
653
+
654
+ index++;
655
+ }
629
656
  }
630
657
  }
631
658
 
632
- function excludes(valueToFind) {
633
- return iterable => !includes(valueToFind)(iterable)
659
+ function exists(predicate) {
660
+ return list => {
661
+ return find(predicate)(list) !== undefined
662
+ }
634
663
  }
635
664
 
636
665
  function filterAsync(predicate) {
@@ -662,22 +691,6 @@ function filterObject(predicate) {
662
691
  }
663
692
  }
664
693
 
665
- function find(predicate) {
666
- return list => {
667
- let index = 0;
668
- const len = list.length;
669
-
670
- while (index < len) {
671
- const x = list[index];
672
- if (predicate(x)) {
673
- return x
674
- }
675
-
676
- index++;
677
- }
678
- }
679
- }
680
-
681
694
  function findIndex(predicate) {
682
695
  return list => {
683
696
  const len = list.length;
@@ -907,40 +920,6 @@ function init(input) {
907
920
  return input.length ? baseSlice(input, 0, -1) : []
908
921
  }
909
922
 
910
- function _includesWith(pred, x, list) {
911
- let idx = 0;
912
- const len = list.length;
913
-
914
- while (idx < len) {
915
- if (pred(x, list[idx])) {
916
- return true
917
- }
918
-
919
- idx += 1;
920
- }
921
-
922
- return false
923
- }
924
- function _filter(fn, list) {
925
- let idx = 0;
926
- const len = list.length;
927
- const result = [];
928
-
929
- while (idx < len) {
930
- if (fn(list[idx])) {
931
- result[result.length] = list[idx];
932
- }
933
-
934
- idx += 1;
935
- }
936
-
937
- return result
938
- }
939
-
940
- function innerJoin(pred, xs) {
941
- return ys => _filter(x => _includesWith(pred, x, ys), xs)
942
- }
943
-
944
923
  const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g);
945
924
  const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '');
946
925
 
@@ -975,6 +954,40 @@ function intersection(listA) {
975
954
  return listB => filter(x => includes(x)(listA))(listB)
976
955
  }
977
956
 
957
+ function _includesWith(pred, x, list) {
958
+ let idx = 0;
959
+ const len = list.length;
960
+
961
+ while (idx < len) {
962
+ if (pred(x, list[idx])) {
963
+ return true
964
+ }
965
+
966
+ idx += 1;
967
+ }
968
+
969
+ return false
970
+ }
971
+ function _filter(fn, list) {
972
+ let idx = 0;
973
+ const len = list.length;
974
+ const result = [];
975
+
976
+ while (idx < len) {
977
+ if (fn(list[idx])) {
978
+ result[result.length] = list[idx];
979
+ }
980
+
981
+ idx += 1;
982
+ }
983
+
984
+ return result
985
+ }
986
+
987
+ function intersectionWith(pred, xs) {
988
+ return ys => _filter(x => _includesWith(pred, x, ys), xs)
989
+ }
990
+
978
991
  function intersperse(separator) {
979
992
  return list => {
980
993
  let index = -1;
@@ -1507,37 +1520,23 @@ function propSatisfies(predicate, property) {
1507
1520
  return obj => predicate(obj[property])
1508
1521
  }
1509
1522
 
1510
- function rangeDescending(start, end) {
1511
- const len = start - end;
1512
- const willReturn = Array(len);
1513
-
1514
- for (let i = 0; i < len; i++) {
1515
- willReturn[i] = start - i;
1516
- }
1517
-
1518
- return willReturn
1523
+ function range(a, b) {
1524
+ const start = b === undefined ? 0 : a;
1525
+ const end = b === undefined ? a : b;
1526
+ if (end<= start) {
1527
+ return []
1528
+ }
1529
+ const len = end - start;
1530
+ return Array.from({ length: len + 1 }, (_, i) => start + i)
1519
1531
  }
1520
1532
 
1521
- function range(start) {
1522
- return end => {
1523
- if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
1524
- throw new TypeError('Both arguments to range must be numbers')
1525
- }
1526
-
1527
- if (end === start) {
1528
- return []
1529
- }
1530
- if (end < start) return rangeDescending(start,end)
1531
-
1532
- const len = end - start;
1533
- const willReturn = Array(len);
1534
-
1535
- for (let i = 0; i < len; i++) {
1536
- willReturn[i] = start + i;
1537
- }
1538
-
1539
- return willReturn
1540
- }
1533
+ function rangeDescending(start, b) {
1534
+ const end = b === undefined ? 0 : b;
1535
+ if (start <= end) {
1536
+ return []
1537
+ }
1538
+ const len = start - end;
1539
+ return Array.from({ length: len + 1 }, (_, i) => start - i)
1541
1540
  }
1542
1541
 
1543
1542
  function replace(pattern, replacer) {
@@ -1785,6 +1784,18 @@ function union(x) {
1785
1784
  }
1786
1785
  }
1787
1786
 
1787
+ function unionWith(predicate, x) {
1788
+ return y => {
1789
+ const filtered = y.filter(yInstance => {
1790
+ return x.every(xInstance => {
1791
+ return !predicate(xInstance, yInstance)
1792
+ })
1793
+ });
1794
+
1795
+ return [...x, ...filtered]
1796
+ }
1797
+ }
1798
+
1788
1799
  function uniq(list) {
1789
1800
  const set = new _Set();
1790
1801
  const willReturn = [];
@@ -1910,6 +1921,7 @@ exports.createCompareFunction = createCompareFunction;
1910
1921
  exports.createObjectFromKeys = createObjectFromKeys;
1911
1922
  exports.defaultTo = defaultTo;
1912
1923
  exports.descend = descend;
1924
+ exports.difference = difference;
1913
1925
  exports.drop = drop;
1914
1926
  exports.dropLast = dropLast;
1915
1927
  exports.dropLastWhile = dropLastWhile;
@@ -1921,6 +1933,7 @@ exports.equals = equals;
1921
1933
  exports.equalsFn = equalsFn;
1922
1934
  exports.evolve = evolve;
1923
1935
  exports.excludes = excludes;
1936
+ exports.exists = exists;
1924
1937
  exports.filter = filter;
1925
1938
  exports.filterAsync = filterAsync;
1926
1939
  exports.filterObject = filterObject;
@@ -1940,9 +1953,9 @@ exports.includes = includes;
1940
1953
  exports.indexBy = indexBy;
1941
1954
  exports.indexOf = indexOf;
1942
1955
  exports.init = init;
1943
- exports.innerJoin = innerJoin;
1944
1956
  exports.interpolate = interpolate;
1945
1957
  exports.intersection = intersection;
1958
+ exports.intersectionWith = intersectionWith;
1946
1959
  exports.intersperse = intersperse;
1947
1960
  exports.join = join;
1948
1961
  exports.last = last;
@@ -1982,6 +1995,7 @@ exports.propEq = propEq;
1982
1995
  exports.propOr = propOr;
1983
1996
  exports.propSatisfies = propSatisfies;
1984
1997
  exports.range = range;
1998
+ exports.rangeDescending = rangeDescending;
1985
1999
  exports.reduce = reduce;
1986
2000
  exports.reject = reject;
1987
2001
  exports.rejectObject = rejectObject;
@@ -2010,6 +2024,7 @@ exports.transformFlatObject = transformFlatObject;
2010
2024
  exports.tryCatch = tryCatch;
2011
2025
  exports.type = type;
2012
2026
  exports.union = union;
2027
+ exports.unionWith = unionWith;
2013
2028
  exports.uniq = uniq;
2014
2029
  exports.uniqBy = uniqBy;
2015
2030
  exports.uniqWith = uniqWith;