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.
@@ -262,60 +262,6 @@
262
262
  }
263
263
  }
264
264
 
265
- function drop(howManyToDrop, ) {
266
- return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
267
- }
268
-
269
- function dropLast(numberItems) {
270
- return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
271
- }
272
-
273
- function dropLastWhile(predicate) {
274
- return list => {
275
- if (list.length === 0) {
276
- return list
277
- }
278
-
279
- const toReturn = [];
280
- let counter = list.length;
281
-
282
- while (counter) {
283
- const item = list[--counter];
284
- if (!predicate(item, counter)) {
285
- toReturn.push(item);
286
- break
287
- }
288
- }
289
-
290
- while (counter) {
291
- toReturn.push(list[--counter]);
292
- }
293
-
294
- return toReturn.reverse()
295
- }
296
- }
297
-
298
- function dropWhile(predicate) {
299
- return iterable => {
300
- const toReturn = [];
301
- let counter = 0;
302
-
303
- while (counter < iterable.length) {
304
- const item = iterable[counter++];
305
- if (!predicate(item, counter)) {
306
- toReturn.push(item);
307
- break
308
- }
309
- }
310
-
311
- while (counter < iterable.length) {
312
- toReturn.push(iterable[counter++]);
313
- }
314
-
315
- return toReturn
316
- }
317
- }
318
-
319
265
  function type(input) {
320
266
  if (input === null) {
321
267
  return 'Null'
@@ -539,6 +485,83 @@
539
485
  return b => equalsFn(a, b)
540
486
  }
541
487
 
488
+ function includes(valueToFind) {
489
+ return iterable => {
490
+ if (typeof iterable === 'string') {
491
+ return iterable.includes(valueToFind)
492
+ }
493
+ if (!iterable) {
494
+ throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
495
+ }
496
+ if (!isArray(iterable)) {
497
+ return false
498
+ }
499
+
500
+ return _indexOf(valueToFind, iterable) > -1
501
+ }
502
+ }
503
+
504
+ function difference(x) {
505
+ return y => ([
506
+ ...filter(value => !includes(value)(y))(x),
507
+ ...filter(value => !includes(value)(x))(y),
508
+ ])
509
+ }
510
+
511
+ function drop(howManyToDrop, ) {
512
+ return list => list.slice(howManyToDrop > 0 ? howManyToDrop : 0)
513
+ }
514
+
515
+ function dropLast(numberItems) {
516
+ return list => (numberItems > 0 ? list.slice(0, -numberItems) : list.slice())
517
+ }
518
+
519
+ function dropLastWhile(predicate) {
520
+ return list => {
521
+ if (list.length === 0) {
522
+ return list
523
+ }
524
+
525
+ const toReturn = [];
526
+ let counter = list.length;
527
+
528
+ while (counter) {
529
+ const item = list[--counter];
530
+ if (!predicate(item, counter)) {
531
+ toReturn.push(item);
532
+ break
533
+ }
534
+ }
535
+
536
+ while (counter) {
537
+ toReturn.push(list[--counter]);
538
+ }
539
+
540
+ return toReturn.reverse()
541
+ }
542
+ }
543
+
544
+ function dropWhile(predicate) {
545
+ return iterable => {
546
+ const toReturn = [];
547
+ let counter = 0;
548
+
549
+ while (counter < iterable.length) {
550
+ const item = iterable[counter++];
551
+ if (!predicate(item, counter)) {
552
+ toReturn.push(item);
553
+ break
554
+ }
555
+ }
556
+
557
+ while (counter < iterable.length) {
558
+ toReturn.push(iterable[counter++]);
559
+ }
560
+
561
+ return toReturn
562
+ }
563
+ }
564
+
542
565
  class _Set {
543
566
  constructor() {
544
567
  this.set = new Set();
@@ -617,24 +640,30 @@
617
640
  return mapObject((x, prop) => type(rules[prop]) === 'Function' ? rules[prop](x): x)
618
641
  }
619
642
 
620
- function includes(valueToFind) {
621
- return iterable => {
622
- if (typeof iterable === 'string') {
623
- return iterable.includes(valueToFind)
624
- }
625
- if (!iterable) {
626
- throw new TypeError(`Cannot read property \'indexOf\' of ${iterable}`)
627
- }
628
- if (!isArray(iterable)) {
629
- return false
630
- }
643
+ function excludes(valueToFind) {
644
+ return iterable => !includes(valueToFind)(iterable)
645
+ }
631
646
 
632
- return _indexOf(valueToFind, iterable) > -1
647
+ function find(predicate) {
648
+ return list => {
649
+ let index = 0;
650
+ const len = list.length;
651
+
652
+ while (index < len) {
653
+ const x = list[index];
654
+ if (predicate(x)) {
655
+ return x
656
+ }
657
+
658
+ index++;
659
+ }
633
660
  }
634
661
  }
635
662
 
636
- function excludes(valueToFind) {
637
- return iterable => !includes(valueToFind)(iterable)
663
+ function exists(predicate) {
664
+ return list => {
665
+ return find(predicate)(list) !== undefined
666
+ }
638
667
  }
639
668
 
640
669
  function filterAsync(predicate) {
@@ -666,22 +695,6 @@
666
695
  }
667
696
  }
668
697
 
669
- function find(predicate) {
670
- return list => {
671
- let index = 0;
672
- const len = list.length;
673
-
674
- while (index < len) {
675
- const x = list[index];
676
- if (predicate(x)) {
677
- return x
678
- }
679
-
680
- index++;
681
- }
682
- }
683
- }
684
-
685
698
  function findIndex(predicate) {
686
699
  return list => {
687
700
  const len = list.length;
@@ -911,40 +924,6 @@
911
924
  return input.length ? baseSlice(input, 0, -1) : []
912
925
  }
913
926
 
914
- function _includesWith(pred, x, list) {
915
- let idx = 0;
916
- const len = list.length;
917
-
918
- while (idx < len) {
919
- if (pred(x, list[idx])) {
920
- return true
921
- }
922
-
923
- idx += 1;
924
- }
925
-
926
- return false
927
- }
928
- function _filter(fn, list) {
929
- let idx = 0;
930
- const len = list.length;
931
- const result = [];
932
-
933
- while (idx < len) {
934
- if (fn(list[idx])) {
935
- result[result.length] = list[idx];
936
- }
937
-
938
- idx += 1;
939
- }
940
-
941
- return result
942
- }
943
-
944
- function innerJoin(pred, xs) {
945
- return ys => _filter(x => _includesWith(pred, x, ys), xs)
946
- }
947
-
948
927
  const getOccurrences = input => input.match(/{{\s*.+?\s*}}/g);
949
928
  const getOccurrenceProp = occurrence => occurrence.replace(/{{\s*|\s*}}/g, '');
950
929
 
@@ -979,6 +958,40 @@
979
958
  return listB => filter(x => includes(x)(listA))(listB)
980
959
  }
981
960
 
961
+ function _includesWith(pred, x, list) {
962
+ let idx = 0;
963
+ const len = list.length;
964
+
965
+ while (idx < len) {
966
+ if (pred(x, list[idx])) {
967
+ return true
968
+ }
969
+
970
+ idx += 1;
971
+ }
972
+
973
+ return false
974
+ }
975
+ function _filter(fn, list) {
976
+ let idx = 0;
977
+ const len = list.length;
978
+ const result = [];
979
+
980
+ while (idx < len) {
981
+ if (fn(list[idx])) {
982
+ result[result.length] = list[idx];
983
+ }
984
+
985
+ idx += 1;
986
+ }
987
+
988
+ return result
989
+ }
990
+
991
+ function intersectionWith(pred, xs) {
992
+ return ys => _filter(x => _includesWith(pred, x, ys), xs)
993
+ }
994
+
982
995
  function intersperse(separator) {
983
996
  return list => {
984
997
  let index = -1;
@@ -1511,37 +1524,23 @@
1511
1524
  return obj => predicate(obj[property])
1512
1525
  }
1513
1526
 
1514
- function rangeDescending(start, end) {
1515
- const len = start - end;
1516
- const willReturn = Array(len);
1517
-
1518
- for (let i = 0; i < len; i++) {
1519
- willReturn[i] = start - i;
1520
- }
1521
-
1522
- return willReturn
1527
+ function range(a, b) {
1528
+ const start = b === undefined ? 0 : a;
1529
+ const end = b === undefined ? a : b;
1530
+ if (end<= start) {
1531
+ return []
1532
+ }
1533
+ const len = end - start;
1534
+ return Array.from({ length: len + 1 }, (_, i) => start + i)
1523
1535
  }
1524
1536
 
1525
- function range(start) {
1526
- return end => {
1527
- if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
1528
- throw new TypeError('Both arguments to range must be numbers')
1529
- }
1530
-
1531
- if (end === start) {
1532
- return []
1533
- }
1534
- if (end < start) return rangeDescending(start,end)
1535
-
1536
- const len = end - start;
1537
- const willReturn = Array(len);
1538
-
1539
- for (let i = 0; i < len; i++) {
1540
- willReturn[i] = start + i;
1541
- }
1542
-
1543
- return willReturn
1544
- }
1537
+ function rangeDescending(start, b) {
1538
+ const end = b === undefined ? 0 : b;
1539
+ if (start <= end) {
1540
+ return []
1541
+ }
1542
+ const len = start - end;
1543
+ return Array.from({ length: len + 1 }, (_, i) => start - i)
1545
1544
  }
1546
1545
 
1547
1546
  function replace(pattern, replacer) {
@@ -1789,6 +1788,18 @@
1789
1788
  }
1790
1789
  }
1791
1790
 
1791
+ function unionWith(predicate, x) {
1792
+ return y => {
1793
+ const filtered = y.filter(yInstance => {
1794
+ return x.every(xInstance => {
1795
+ return !predicate(xInstance, yInstance)
1796
+ })
1797
+ });
1798
+
1799
+ return [...x, ...filtered]
1800
+ }
1801
+ }
1802
+
1792
1803
  function uniq(list) {
1793
1804
  const set = new _Set();
1794
1805
  const willReturn = [];
@@ -1914,6 +1925,7 @@
1914
1925
  exports.createObjectFromKeys = createObjectFromKeys;
1915
1926
  exports.defaultTo = defaultTo;
1916
1927
  exports.descend = descend;
1928
+ exports.difference = difference;
1917
1929
  exports.drop = drop;
1918
1930
  exports.dropLast = dropLast;
1919
1931
  exports.dropLastWhile = dropLastWhile;
@@ -1925,6 +1937,7 @@
1925
1937
  exports.equalsFn = equalsFn;
1926
1938
  exports.evolve = evolve;
1927
1939
  exports.excludes = excludes;
1940
+ exports.exists = exists;
1928
1941
  exports.filter = filter;
1929
1942
  exports.filterAsync = filterAsync;
1930
1943
  exports.filterObject = filterObject;
@@ -1944,9 +1957,9 @@
1944
1957
  exports.indexBy = indexBy;
1945
1958
  exports.indexOf = indexOf;
1946
1959
  exports.init = init;
1947
- exports.innerJoin = innerJoin;
1948
1960
  exports.interpolate = interpolate;
1949
1961
  exports.intersection = intersection;
1962
+ exports.intersectionWith = intersectionWith;
1950
1963
  exports.intersperse = intersperse;
1951
1964
  exports.join = join;
1952
1965
  exports.last = last;
@@ -1986,6 +1999,7 @@
1986
1999
  exports.propOr = propOr;
1987
2000
  exports.propSatisfies = propSatisfies;
1988
2001
  exports.range = range;
2002
+ exports.rangeDescending = rangeDescending;
1989
2003
  exports.reduce = reduce;
1990
2004
  exports.reject = reject;
1991
2005
  exports.rejectObject = rejectObject;
@@ -2014,6 +2028,7 @@
2014
2028
  exports.tryCatch = tryCatch;
2015
2029
  exports.type = type;
2016
2030
  exports.union = union;
2031
+ exports.unionWith = unionWith;
2017
2032
  exports.uniq = uniq;
2018
2033
  exports.uniqBy = uniqBy;
2019
2034
  exports.uniqWith = uniqWith;
package/index.d.cts CHANGED
@@ -88,6 +88,8 @@ MergeTypes<
88
88
 
89
89
  type StrictNonNullable<T> = Exclude<T, null | undefined>;
90
90
 
91
+ type ExcludeFalsy<T> = Exclude<T, null | undefined | false | true | 0 | "">;
92
+
91
93
  type Flatten<T> = T extends object
92
94
  ? T extends readonly any[]
93
95
  ? T
@@ -198,8 +200,8 @@ export function anyPass<F extends (...args: any[]) => boolean>(predicates: reado
198
200
  /**
199
201
  * It adds element `x` at the end of `iterable`.
200
202
  */
201
- export function append<T>(el: T): (list: T[]) => T[];
202
203
  export function append<T>(el: T): (list: readonly T[]) => T[];
204
+ export function append<T>(el: T): (list: T[]) => T[];
203
205
 
204
206
  /**
205
207
  * Helper function to be used with `R.sort` to sort list in ascending order.
@@ -275,6 +277,13 @@ export function defaultTo<T>(defaultValue: T): (input: unknown) => T;
275
277
  */
276
278
  export function descend<T>(fn: (obj: T) => Ord): (a: T, b: T)=> Ordering;
277
279
 
280
+ /**
281
+ * It returns a merged list of `x` and `y` with all equal elements removed.
282
+ *
283
+ * `R.equals` is used to determine equality.
284
+ */
285
+ export function difference<T>(x: T[]): (y: T[]) => T[];
286
+
278
287
  /**
279
288
  * It returns `howMany` items dropped from beginning of list.
280
289
  */
@@ -323,8 +332,13 @@ export function evolve<T>(rules: {
323
332
  *
324
333
  * `R.equals` is used to determine equality.
325
334
  */
326
- export function excludes<T extends string>(valueToFind: T): (input: string) => boolean;
327
- export function excludes<T>(valueToFind: T): (input: T[]) => boolean;
335
+ export function excludes(list: readonly string[] | string): (substringToFind: string) => boolean;
336
+ export function excludes<T>(list: readonly T[]): (target: T) => boolean;
337
+
338
+ /**
339
+ * It returns `true` if there is at least one element in `list` that satisfy the `predicate`.
340
+ */
341
+ export function exists<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
328
342
 
329
343
  /**
330
344
  * It filters list or object `input` using a `predicate` function.
@@ -334,10 +348,10 @@ export function filter<T, S extends T>(
334
348
  ): (list: T[]) => S[];
335
349
  export function filter<T>(
336
350
  predicate: BooleanConstructor,
337
- ): (list: readonly T[]) => StrictNonNullable<T>[];
351
+ ): (list: readonly T[]) => ExcludeFalsy<T>[];
338
352
  export function filter<T>(
339
353
  predicate: BooleanConstructor,
340
- ): (list: T[]) => StrictNonNullable<T>[];
354
+ ): (list: T[]) => ExcludeFalsy<T>[];
341
355
  export function filter<T>(
342
356
  predicate: (value: T) => boolean,
343
357
  ): (list: T[]) => T[];
@@ -428,8 +442,8 @@ export function head<T>(listOrString: T): T extends string ? string :
428
442
  *
429
443
  * If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list.
430
444
  */
431
- export function includes(s: string): (list: readonly string[] | string) => boolean;
432
- export function includes<T>(target: T): (list: readonly T[]) => boolean;
445
+ export function includes<T>(list: readonly T[]): (target: T) => boolean;
446
+ export function includes(list: readonly string[] | string): (substringToFind: string) => boolean;
433
447
 
434
448
  /**
435
449
  * It transforms list of objects to object using specified property as the base for the returned object.
@@ -455,14 +469,6 @@ export function indexOf<T>(valueToFind: T): (list: T[]) => number;
455
469
  export function init<T extends unknown[]>(input: T): T extends readonly [...infer U, any] ? U : [...T];
456
470
  export function init(input: string): string;
457
471
 
458
- /**
459
- * It returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.
460
- */
461
- export function innerJoin<T1, T2>(
462
- pred: (a: T1, b: T2) => boolean,
463
- list1: T1[],
464
- ): (list2: T2[]) => T1[];
465
-
466
472
  /**
467
473
  * It generates a new string from `inputWithTags` by replacing all `{{x}}` occurrences with values provided by `templateArguments`.
468
474
  */
@@ -473,6 +479,14 @@ export function interpolate(inputWithTags: string): (templateArguments: object)
473
479
  */
474
480
  export function intersection<T>(listA: T[]): (listB: T[]) => T[];
475
481
 
482
+ /**
483
+ * It returns a new list by applying a `predicate` function to all elements of `list1` and `list2` and keeping only these elements where `predicate` returns `true`.
484
+ */
485
+ export function intersectionWith<T1, T2>(
486
+ pred: (a: T1, b: T2) => boolean,
487
+ list1: T1[],
488
+ ): (list2: T2[]) => T1[];
489
+
476
490
  /**
477
491
  * It adds a `separator` between members of `list`.
478
492
  */
@@ -1778,10 +1792,16 @@ export function propOr<T, P extends string>(property: P, defaultValue: T): (obj:
1778
1792
  export function propSatisfies<T>(predicate: (x: T) => boolean, property: string): (obj: Record<PropertyKey, T>) => boolean;
1779
1793
 
1780
1794
  /**
1781
- * It returns list of numbers between `startInclusive` to `endExclusive` markers.
1782
- * If `start` is greater than `end`, then the result will be in descending order.
1795
+ * It returns list of numbers between `startInclusive` to `endInclusive` markers.
1783
1796
  */
1784
- export function range(startInclusive: number): (endExclusive: number) => number[];
1797
+ export function range(endInclusive: number) : number[];
1798
+ export function range(startInclusive: number, endInclusive: number) : number[];
1799
+
1800
+ /**
1801
+ * It returns list of numbers between `endInclusive` to `startInclusive` markers.
1802
+ */
1803
+ export function rangeDescending(startInclusive: number, endInclusive: number) : number[];
1804
+ export function rangeDescending(endInclusive: number) : number[];
1785
1805
 
1786
1806
  export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult, initialValue: TResult): (list: T[]) => TResult;
1787
1807
 
@@ -2189,11 +2209,11 @@ export function split(separator: string | RegExp): (str: string) => string[];
2189
2209
  export function splitEvery<T>(sliceLength: number): (input: T[]) => (T[])[];
2190
2210
 
2191
2211
  /**
2192
- * It returns a merged list of `x` and `y` with all equal elements removed.
2212
+ * It returns all items that are in either of the lists, but not in both.
2193
2213
  *
2194
2214
  * `R.equals` is used to determine equality.
2195
2215
  */
2196
- export function symmetricDifference<T>(x: T[]): <T>(y: T[]) => T[];
2216
+ export function symmetricDifference<T>(x: T[]): (y: T[]) => T[];
2197
2217
 
2198
2218
  /**
2199
2219
  * It returns all but the first element of `input`.
@@ -2206,8 +2226,8 @@ export function tail(input: string): string;
2206
2226
  */
2207
2227
  export function take<T>(howMany: number): {
2208
2228
  (input: string): string;
2209
- (input: T[]): T[];
2210
2229
  (input: readonly T[]): T[];
2230
+ (input: T[]): T[];
2211
2231
  };
2212
2232
 
2213
2233
  /**
@@ -2215,8 +2235,8 @@ export function take<T>(howMany: number): {
2215
2235
  */
2216
2236
  export function takeLast<T>(howMany: number): {
2217
2237
  (input: string): string;
2218
- (input: T[]): T[];
2219
2238
  (input: readonly T[]): T[];
2239
+ (input: T[]): T[];
2220
2240
  };
2221
2241
 
2222
2242
  export function takeLastWhile<T>(predicate: (x: T) => boolean): (input: T[]) => T[];
@@ -2262,6 +2282,8 @@ export function type(x: any): RambdaTypes;
2262
2282
  */
2263
2283
  export function union<T>(x: T[]): (y: T[]) => T[];
2264
2284
 
2285
+ export function unionWith<T>(predicate: (x: T, y: T) => boolean, x: T[]): (y: T[]) => T[];
2286
+
2265
2287
  /**
2266
2288
  * It returns a new array containing only one copy of each element of `list`.
2267
2289
  *