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/index.d.ts 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
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rambda",
3
- "version": "10.3.4",
3
+ "version": "11.0.0",
4
4
  "scripts": {
5
5
  "out": "yarn populatedocs && yarn populatereadme && yarn build && yarn create-docsify",
6
6
  "build": "yarn build:main && yarn build:web && yarn build:esm",
package/rambda.js CHANGED
@@ -18,6 +18,7 @@ export * from './src/countBy.js'
18
18
  export * from './src/createObjectFromKeys.js'
19
19
  export * from './src/defaultTo.js'
20
20
  export * from './src/descend.js'
21
+ export * from './src/difference.js'
21
22
  export * from './src/drop.js'
22
23
  export * from './src/dropLast.js'
23
24
  export * from './src/dropLastWhile.js'
@@ -28,6 +29,7 @@ export * from './src/eqProps.js'
28
29
  export * from './src/equals.js'
29
30
  export * from './src/evolve.js'
30
31
  export * from './src/excludes.js'
32
+ export * from './src/exists.js'
31
33
  export * from './src/filter.js'
32
34
  export * from './src/filterAsync.js'
33
35
  export * from './src/filterObject.js'
@@ -45,9 +47,9 @@ export * from './src/includes.js'
45
47
  export * from './src/indexBy.js'
46
48
  export * from './src/indexOf.js'
47
49
  export * from './src/init.js'
48
- export * from './src/innerJoin.js'
49
50
  export * from './src/interpolate.js'
50
51
  export * from './src/intersection.js'
52
+ export * from './src/intersectionWith.js'
51
53
  export * from './src/intersperse.js'
52
54
  export * from './src/join.js'
53
55
  export * from './src/last.js'
@@ -86,6 +88,7 @@ export * from './src/propEq.js'
86
88
  export * from './src/propOr.js'
87
89
  export * from './src/propSatisfies.js'
88
90
  export * from './src/range.js'
91
+ export * from './src/rangeDescending.js'
89
92
  export * from './src/reduce.js'
90
93
  export * from './src/reject.js'
91
94
  export * from './src/rejectObject.js'
@@ -112,6 +115,7 @@ export * from './src/test.js'
112
115
  export * from './src/tryCatch.js'
113
116
  export * from './src/type.js'
114
117
  export * from './src/union.js'
118
+ export * from './src/unionWith.js'
115
119
  export * from './src/uniq.js'
116
120
  export * from './src/uniqBy.js'
117
121
  export * from './src/uniqWith.js'
@@ -0,0 +1,9 @@
1
+ import { filter } from './filter.js'
2
+ import { includes } from './includes.js'
3
+
4
+ export function difference(x) {
5
+ return y => ([
6
+ ...filter(value => !includes(value)(y))(x),
7
+ ...filter(value => !includes(value)(x))(y),
8
+ ])
9
+ }
package/src/exists.js ADDED
@@ -0,0 +1,7 @@
1
+ import { find } from './find.js'
2
+
3
+ export function exists(predicate) {
4
+ return list => {
5
+ return find(predicate)(list) !== undefined
6
+ }
7
+ }
@@ -28,6 +28,6 @@ function _filter(fn, list) {
28
28
  return result
29
29
  }
30
30
 
31
- export function innerJoin(pred, xs) {
31
+ export function intersectionWith(pred, xs) {
32
32
  return ys => _filter(x => _includesWith(pred, x, ys), xs)
33
33
  }
package/src/range.js CHANGED
@@ -1,34 +1,9 @@
1
- function rangeDescending(start, end) {
2
- const len = start - end
3
- const willReturn = Array(len)
4
-
5
- for (let i = 0; i < len; i++) {
6
- willReturn[i] = start - i
7
- }
8
-
9
- return willReturn
10
- }
11
-
12
- export function range(start) {
13
- return end => {
14
- if (Number.isNaN(Number(start)) || Number.isNaN(Number(end))) {
15
- throw new TypeError('Both arguments to range must be numbers')
16
- }
17
-
18
- if (end === start) {
19
- return []
20
- }
21
- if (end < start) return rangeDescending(start,end)
22
-
23
- const len = end - start
24
- const willReturn = Array(len)
25
-
26
- for (let i = 0; i < len; i++) {
27
- willReturn[i] = start + i
28
- }
29
-
30
- return willReturn
1
+ export function range(a, b) {
2
+ const start = b === undefined ? 0 : a
3
+ const end = b === undefined ? a : b
4
+ if (end<= start) {
5
+ return []
31
6
  }
7
+ const len = end - start
8
+ return Array.from({ length: len + 1 }, (_, i) => start + i)
32
9
  }
33
-
34
-
@@ -0,0 +1,8 @@
1
+ export function rangeDescending(start, b) {
2
+ const end = b === undefined ? 0 : b
3
+ if (start <= end) {
4
+ return []
5
+ }
6
+ const len = start - end
7
+ return Array.from({ length: len + 1 }, (_, i) => start - i)
8
+ }
@@ -0,0 +1,11 @@
1
+ export function unionWith(predicate, x) {
2
+ return y => {
3
+ const filtered = y.filter(yInstance => {
4
+ return x.every(xInstance => {
5
+ return !predicate(xInstance, yInstance)
6
+ })
7
+ })
8
+
9
+ return [...x, ...filtered]
10
+ }
11
+ }