rambda 8.6.0 → 9.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
@@ -43,10 +43,7 @@ interface KeyValuePair<K, V> extends Array<K | V> {
43
43
  1: V;
44
44
  }
45
45
 
46
- export interface Lens {
47
- <T, U>(obj: T): U;
48
- set<T, U>(str: string, obj: T): U;
49
- }
46
+ export type Lens<S, A> = (functorFactory: (a: A) => Functor<A>) => (s: S) => Functor<S>;
50
47
 
51
48
  type Arity1Fn = (x: any) => any;
52
49
  type Arity2Fn = (x: any, y: any) => any;
@@ -147,12 +144,12 @@ interface SchemaAsync {
147
144
  [key: string]: Promise<boolean>;
148
145
  }
149
146
 
150
- interface IsValid {
147
+ export interface IsValid {
151
148
  input: object;
152
149
  schema: Schema;
153
150
  }
154
151
 
155
- interface IsValidAsync {
152
+ export interface IsValidAsync {
156
153
  input: object;
157
154
  schema: Schema | SchemaAsync;
158
155
  }
@@ -174,8 +171,6 @@ type ApplyDiffAdd = {op:'add', path: string, value: any};
174
171
  type ApplyDiffRemove = {op:'remove', path: string};
175
172
  type ApplyDiffRule = ApplyDiffUpdate | ApplyDiffAdd | ApplyDiffRemove;
176
173
 
177
- type Resolved<T> = {status: 'fulfilled', value: T} | {status: 'rejected', reason: string|Error}
178
-
179
174
 
180
175
  export function F(): boolean;
181
176
 
@@ -190,6 +185,9 @@ export function add(a: number): (b: number) => number;
190
185
  export function addIndex(originalFn: any): (fn: any) => (list: any[]) => any[];
191
186
  export function addIndex(originalFn: any): (fn: any, list: any[]) => any[];
192
187
 
188
+ /**
189
+ * Same as `R.addIndex`, but it will passed indexes are decreasing, instead of increasing.
190
+ */
193
191
  export function addIndexRight(originalFn: any): (fn: any) => (list: any[]) => any[];
194
192
  export function addIndexRight(originalFn: any): (fn: any, list: any[]) => any[];
195
193
 
@@ -234,10 +232,16 @@ export function any<T>(predicate: (x: T) => boolean): (list: T[]) => boolean;
234
232
  export function anyPass<T>(predicates: ((x: T) => boolean)[]): (input: T) => boolean;
235
233
  export function anyPass<T>(predicates: ((...inputs: T[]) => boolean)[]): (...inputs: T[]) => boolean;
236
234
 
235
+ /**
236
+ * It takes a list of functions and a list of values. Then it returns a list of values obtained by applying each function to each value.
237
+ */
237
238
  export function ap<T, U>(fns: Array<(a: T) => U>[], vs: T[]): U[];
238
239
  export function ap<T, U>(fns: Array<(a: T) => U>): (vs: T[]) => U[];
239
240
  export function ap<R, A, B>(fn: (r: R, a: A) => B, fn1: (r: R) => A): (r: R) => B;
240
241
 
242
+ /**
243
+ * It returns a new list, composed of consecutive `n`-tuples from a `list`.
244
+ */
241
245
  export function aperture<N extends number, T>(n: N, list: T[]): Array<Tuple<T, N>> | [];
242
246
  export function aperture<N extends number>(n: N): <T>(list: T[]) => Array<Tuple<T, N>> | [];
243
247
 
@@ -329,6 +333,9 @@ export function clone<T>(input: T[]): T[];
329
333
  export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K, list: T[]): T[][];
330
334
  export function collectBy<T, K extends PropertyKey>(keyFn: (value: T) => K): (list: T[]) => T[][];
331
335
 
336
+ /**
337
+ * It returns a comparator function that can be used in `sort` method.
338
+ */
332
339
  export function comparator<T>(pred: (a: T, b: T) => boolean): (x: T, y: T) => Ordering;
333
340
 
334
341
  /**
@@ -353,7 +360,7 @@ export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult
353
360
  f2: (a: R1) => R2,
354
361
  f1: (...args: TArgs) => R1
355
362
  ]
356
- ): (...args: TArgs) => TResult; // fallback overload if number of composed functions greater than 7
363
+ ): (...args: TArgs) => TResult;
357
364
  export function compose<TArgs extends any[], R1, R2, R3, R4, R5, R6, R7, TResult>(
358
365
  f7: (a: R6) => R7,
359
366
  f6: (a: R5) => R6,
@@ -686,12 +693,19 @@ export function groupWith<T>(compareFn: (x: T, y: T) => boolean): (input: T[]) =
686
693
  export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: T[]): (T[])[];
687
694
  export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: string): string[];
688
695
 
696
+ export function gt<T>(x: T): T;
697
+
698
+ export function gte<T>(x: T): T;
699
+
689
700
  /**
690
701
  * It returns `true` if `obj` has property `prop`.
691
702
  */
692
703
  export function has<T>(prop: string, obj: T): boolean;
693
704
  export function has(prop: string): <T>(obj: T) => boolean;
694
705
 
706
+ export function hasIn(searchProperty: string): <T>(obj: T) => boolean;
707
+ export function hasIn<T>(searchProperty: string, obj: T): boolean;
708
+
695
709
  /**
696
710
  * It will return true, if `input` object has truthy `path`(calculated with `R.path`).
697
711
  */
@@ -780,6 +794,18 @@ export function indexOf<T>(valueToFind: T): (list: T[]) => number;
780
794
  export function init<T extends unknown[]>(input: T): T extends readonly [...infer U, any] ? U : [...T];
781
795
  export function init(input: string): string;
782
796
 
797
+ /**
798
+ * 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`.
799
+ */
800
+ export function innerJoin<T1, T2>(
801
+ pred: (a: T1, b: T2) => boolean,
802
+ ): (list1: T1[], list2: T2[]) => T1[];
803
+ export function innerJoin<T1, T2>(
804
+ pred: (a: T1, b: T2) => boolean,
805
+ list1: T1[],
806
+ ): (list2: T2[]) => T1[];
807
+ export function innerJoin<T1, T2>(pred: (a: T1, b: T2) => boolean, list1: T1[], list2: T2[]): T1[];
808
+
783
809
  /**
784
810
  * It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
785
811
  */
@@ -863,26 +889,57 @@ export function length<T>(input: T[]): number;
863
889
  *
864
890
  * The setter should not mutate the data structure.
865
891
  */
866
- export function lens<T, U, V>(getter: (s: T) => U, setter: (a: U, s: T) => V): Lens;
892
+ export function lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>;
867
893
 
868
894
  /**
869
895
  * It returns a lens that focuses on specified `index`.
870
896
  */
871
- export function lensIndex(index: number): Lens;
897
+ export function lensIndex<A>(n: number): Lens<A[], A>;
898
+ export function lensIndex<A extends any[], N extends number>(n: N): Lens<A, A[N]>;
872
899
 
873
900
  /**
874
901
  * It returns a lens that focuses on specified `path`.
875
902
  */
876
- export function lensPath(path: RamdaPath): Lens;
877
- export function lensPath(path: string): Lens;
903
+ export function lensPath<S, K0 extends keyof S = keyof S>(path: [K0]): Lens<S, S[K0]>;
904
+ export function lensPath<S, K0 extends keyof S = keyof S, K1 extends keyof S[K0] = keyof S[K0]>(
905
+ path: [K0, K1],
906
+ ): Lens<S, S[K0][K1]>;
907
+ export function lensPath<
908
+ S,
909
+ K0 extends keyof S = keyof S,
910
+ K1 extends keyof S[K0] = keyof S[K0],
911
+ K2 extends keyof S[K0][K1] = keyof S[K0][K1]
912
+ >(path: [K0, K1, K2]): Lens<S, S[K0][K1][K2]>;
913
+ export function lensPath<
914
+ S,
915
+ K0 extends keyof S = keyof S,
916
+ K1 extends keyof S[K0] = keyof S[K0],
917
+ K2 extends keyof S[K0][K1] = keyof S[K0][K1],
918
+ K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2]
919
+ >(path: [K0, K1, K2, K3]): Lens<S, S[K0][K1][K2][K3]>;
920
+ export function lensPath<
921
+ S,
922
+ K0 extends keyof S = keyof S,
923
+ K1 extends keyof S[K0] = keyof S[K0],
924
+ K2 extends keyof S[K0][K1] = keyof S[K0][K1],
925
+ K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
926
+ K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3]
927
+ >(path: [K0, K1, K2, K3, K4]): Lens<S, S[K0][K1][K2][K3][K4]>;
928
+ export function lensPath<
929
+ S,
930
+ K0 extends keyof S = keyof S,
931
+ K1 extends keyof S[K0] = keyof S[K0],
932
+ K2 extends keyof S[K0][K1] = keyof S[K0][K1],
933
+ K3 extends keyof S[K0][K1][K2] = keyof S[K0][K1][K2],
934
+ K4 extends keyof S[K0][K1][K2][K3] = keyof S[K0][K1][K2][K3],
935
+ K5 extends keyof S[K0][K1][K2][K3][K4] = keyof S[K0][K1][K2][K3][K4]
936
+ >(path: [K0, K1, K2, K3, K4, K5]): Lens<S, S[K0][K1][K2][K3][K4][K5]>;
937
+ export function lensPath<S = any, A = any>(path: Path): Lens<S, A>;
878
938
 
879
939
  /**
880
940
  * It returns a lens that focuses on specified property `prop`.
881
941
  */
882
- export function lensProp(prop: string): {
883
- <T, U>(obj: T): U;
884
- set<T, U, V>(val: T, obj: U): V;
885
- };
942
+ export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;
886
943
 
887
944
  /**
888
945
  * It returns the result of looping through `iterable` with `fn`.
@@ -1393,6 +1450,25 @@ export function reduce<T, TResult>(reducer: (prev: TResult, current: T) => TResu
1393
1450
  export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult): (initialValue: TResult, list: T[]) => TResult;
1394
1451
  export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult, initialValue: TResult): (list: T[]) => TResult;
1395
1452
 
1453
+ export function reduceBy<T, TResult>(
1454
+ valueFn: (acc: TResult, elem: T) => TResult,
1455
+ ): (a: TResult, b: (elem: T) => string, c: T[]) => { [index: string]: TResult }
1456
+ export function reduceBy<T, TResult>(
1457
+ valueFn: (acc: TResult, elem: T) => TResult,
1458
+ acc: TResult,
1459
+ ): (a: (elem: T) => string, b: T[]) => { [index: string]: TResult }
1460
+ export function reduceBy<T, TResult>(
1461
+ valueFn: (acc: TResult, elem: T) => TResult,
1462
+ acc: TResult,
1463
+ keyFn: (elem: T) => string,
1464
+ ): (list: T[]) => { [index: string]: TResult };
1465
+ export function reduceBy<T, TResult>(
1466
+ valueFn: (acc: TResult, elem: T) => TResult,
1467
+ acc: TResult,
1468
+ keyFn: (elem: T) => string,
1469
+ list: T[],
1470
+ ): { [index: string]: TResult };
1471
+
1396
1472
  /**
1397
1473
  * It has the opposite effect of `R.filter`.
1398
1474
  */
@@ -1454,6 +1530,9 @@ export function sortBy<T>(sortFn: (a: T) => Ord, list: T[]): T[];
1454
1530
  export function sortBy<T>(sortFn: (a: T) => Ord): (list: T[]) => T[];
1455
1531
  export function sortBy(sortFn: (a: any) => Ord): <T>(list: T[]) => T[];
1456
1532
 
1533
+ export function sortWith<T>(fns: Array<(a: T, b: T) => number>): (list: T[]) => T[];
1534
+ export function sortWith<T>(fns: Array<(a: T, b: T) => number>, list: T[]): T[];
1535
+
1457
1536
  /**
1458
1537
  * Curried version of `String.prototype.split`
1459
1538
  */
@@ -1684,9 +1763,13 @@ export function values<T extends object, K extends keyof T>(obj: T): T[K][];
1684
1763
  /**
1685
1764
  * It returns the value of `lens` focus over `target` object.
1686
1765
  */
1687
- export function view<T, U>(lens: Lens): (target: T) => U;
1688
- export function view<T, U>(lens: Lens, target: T): U;
1766
+ export function view<S, A>(lens: Lens<S, A>): (obj: S) => A;
1767
+ export function view<S, A>(lens: Lens<S, A>, obj: S): A;
1689
1768
 
1769
+ /**
1770
+ * It pass `input` to `predicate` function and if the result is `true`, it will return the result of `whenTrueFn(input)`.
1771
+ * If the `predicate` returns `false`, then it will simply return `input`.
1772
+ */
1690
1773
  export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U, input: T): T | U;
1691
1774
  export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U): (input: T) => T | U;
1692
1775
  export function when<T, U>(predicate: (x: T) => boolean): ((whenTrueFn: (a: T) => U) => (input: T) => T | U);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rambda",
3
- "version": "8.6.0",
3
+ "version": "9.0.0",
4
4
  "scripts": {
5
5
  "benchmark": "cd ../rambda-scripts && RAMBDA_RUN_ALL=ON RAMBDA_RUN_INDEXES=ON yarn benchmark",
6
6
  "benchmark:all": "yarn build:step && cd ../rambda-scripts && yarn benchmark:all",
package/rambda.js CHANGED
@@ -1,4 +1,6 @@
1
1
  /// <reference types="./index.d.ts" />
2
+ export * from './src/F.js'
3
+ export * from './src/T.js'
2
4
  export * from './src/add.js'
3
5
  export * from './src/addIndex.js'
4
6
  export * from './src/addIndexRight.js'
@@ -59,7 +61,6 @@ export * from './src/eqBy.js'
59
61
  export * from './src/eqProps.js'
60
62
  export * from './src/equals.js'
61
63
  export * from './src/evolve.js'
62
- export * from './src/F.js'
63
64
  export * from './src/filter.js'
64
65
  export * from './src/find.js'
65
66
  export * from './src/findIndex.js'
@@ -68,10 +69,14 @@ export * from './src/findLastIndex.js'
68
69
  export * from './src/flatten.js'
69
70
  export * from './src/flip.js'
70
71
  export * from './src/forEach.js'
72
+ export * from './src/forEachObjIndexed.js'
71
73
  export * from './src/fromPairs.js'
72
74
  export * from './src/groupBy.js'
73
75
  export * from './src/groupWith.js'
76
+ export * from './src/gt.js'
77
+ export * from './src/gte.js'
74
78
  export * from './src/has.js'
79
+ export * from './src/hasIn.js'
75
80
  export * from './src/hasPath.js'
76
81
  export * from './src/head.js'
77
82
  export * from './src/identical.js'
@@ -82,6 +87,7 @@ export * from './src/includes.js'
82
87
  export * from './src/indexBy.js'
83
88
  export * from './src/indexOf.js'
84
89
  export * from './src/init.js'
90
+ export * from './src/innerJoin.js'
85
91
  export * from './src/intersection.js'
86
92
  export * from './src/intersperse.js'
87
93
  export * from './src/is.js'
@@ -145,10 +151,11 @@ export * from './src/prop.js'
145
151
  export * from './src/propEq.js'
146
152
  export * from './src/propIs.js'
147
153
  export * from './src/propOr.js'
148
- export * from './src/props.js'
149
154
  export * from './src/propSatisfies.js'
155
+ export * from './src/props.js'
150
156
  export * from './src/range.js'
151
157
  export * from './src/reduce.js'
158
+ export * from './src/reduceBy.js'
152
159
  export * from './src/reject.js'
153
160
  export * from './src/removeIndex.js'
154
161
  export * from './src/repeat.js'
@@ -158,6 +165,7 @@ export * from './src/set.js'
158
165
  export * from './src/slice.js'
159
166
  export * from './src/sort.js'
160
167
  export * from './src/sortBy.js'
168
+ export * from './src/sortWith.js'
161
169
  export * from './src/split.js'
162
170
  export * from './src/splitAt.js'
163
171
  export * from './src/splitEvery.js'
@@ -166,7 +174,6 @@ export * from './src/startsWith.js'
166
174
  export * from './src/subtract.js'
167
175
  export * from './src/sum.js'
168
176
  export * from './src/symmetricDifference.js'
169
- export * from './src/T.js'
170
177
  export * from './src/tail.js'
171
178
  export * from './src/take.js'
172
179
  export * from './src/takeLast.js'
package/src/forEach.js CHANGED
@@ -1,33 +1,8 @@
1
1
  import { isArray } from './_internals/isArray.js'
2
- import { keys } from './_internals/keys.js'
3
-
4
- export function forEachObjIndexedFn(fn, obj){
5
- let index = 0
6
- const listKeys = keys(obj)
7
- const len = listKeys.length
8
-
9
- while (index < len){
10
- const key = listKeys[ index ]
11
- fn(
12
- obj[ key ], key, obj
13
- )
14
- index++
15
- }
16
-
17
- return obj
18
- }
19
-
20
- export function forEachObjIndexed(fn, list){
21
- if (arguments.length === 1) return _list => forEachObjIndexed(fn, _list)
22
-
23
- if (list === undefined) return
24
-
25
- return forEachObjIndexedFn(fn, list)
26
- }
2
+ import { forEachObjIndexedFn } from './forEachObjIndexed.js'
27
3
 
28
4
  export function forEach(fn, iterable){
29
5
  if (arguments.length === 1) return _list => forEach(fn, _list)
30
-
31
6
  if (iterable === undefined) return
32
7
 
33
8
  if (isArray(iterable)){
@@ -0,0 +1,25 @@
1
+ import { keys } from './_internals/keys.js'
2
+
3
+ export function forEachObjIndexedFn(fn, obj){
4
+ let index = 0
5
+ const listKeys = keys(obj)
6
+ const len = listKeys.length
7
+
8
+ while (index < len){
9
+ const key = listKeys[ index ]
10
+ fn(
11
+ obj[ key ], key, obj
12
+ )
13
+ index++
14
+ }
15
+
16
+ return obj
17
+ }
18
+
19
+ export function forEachObjIndexed(fn, list){
20
+ if (arguments.length === 1) return _list => forEachObjIndexed(fn, _list)
21
+
22
+ if (list === undefined) return
23
+
24
+ return forEachObjIndexedFn(fn, list)
25
+ }
package/src/gt.js ADDED
@@ -0,0 +1,6 @@
1
+ export function gt(a, b){
2
+ if (arguments.length === 1)
3
+ return _b => gt(a, _b)
4
+
5
+ return a > b
6
+ }
package/src/gte.js ADDED
@@ -0,0 +1,6 @@
1
+ export function gte(a, b){
2
+ if (arguments.length === 1)
3
+ return _b => gte(a, _b)
4
+
5
+ return a >= b
6
+ }
package/src/hasIn.js ADDED
@@ -0,0 +1,9 @@
1
+ import { propFn } from "./prop";
2
+
3
+ export function hasIn(searchProperty, obj) {
4
+ if (arguments.length === 1){
5
+ return (_obj) => hasIn(searchProperty, _obj);
6
+ }
7
+
8
+ return propFn(searchProperty, obj) !== undefined
9
+ }
@@ -0,0 +1,41 @@
1
+ import { curry } from './curry.js'
2
+
3
+ function _includesWith(
4
+ pred, x, list
5
+ ){
6
+ let idx = 0
7
+ const len = list.length
8
+
9
+ while (idx < len){
10
+ if (pred(x, list[ idx ]))
11
+ return true
12
+
13
+ idx += 1
14
+ }
15
+
16
+ return false
17
+ }
18
+ function _filter(fn, list){
19
+ let idx = 0
20
+ const len = list.length
21
+ const result = []
22
+
23
+ while (idx < len){
24
+ if (fn(list[ idx ]))
25
+ result[ result.length ] = list[ idx ]
26
+
27
+ idx += 1
28
+ }
29
+
30
+ return result
31
+ }
32
+
33
+ export function innerJoinFn(
34
+ pred, xs, ys
35
+ ){
36
+ return _filter(x => _includesWith(
37
+ pred, x, ys
38
+ ), xs)
39
+ }
40
+
41
+ export const innerJoin = curry(innerJoinFn)
package/src/prop.js CHANGED
@@ -1,7 +1,11 @@
1
- export function prop(propToFind, obj){
2
- if (arguments.length === 1) return _obj => prop(propToFind, _obj)
3
-
1
+ export function propFn(searchProperty, obj){
4
2
  if (!obj) return undefined
5
3
 
6
- return obj[ propToFind ]
4
+ return obj[ searchProperty ]
5
+ }
6
+
7
+ export function prop(searchProperty, obj){
8
+ if (arguments.length === 1) return _obj => prop(searchProperty, _obj)
9
+
10
+ return propFn(searchProperty, obj)
7
11
  }
@@ -0,0 +1,29 @@
1
+ import { clone } from './clone.js'
2
+ import { curry } from './curry.js'
3
+ import { has } from './has.js'
4
+ import { reduce } from './reduce.js'
5
+
6
+ function reduceByFunction(
7
+ valueFn, valueAcc, keyFn, acc, elt
8
+ ){
9
+ const key = keyFn(elt)
10
+ const value = valueFn(has(key, acc) ? acc[ key ] : clone(valueAcc), elt)
11
+
12
+ acc[ key ] = value
13
+
14
+ return acc
15
+ }
16
+
17
+ export function reduceByFn(
18
+ valueFn, valueAcc, keyFn, list
19
+ ){
20
+ return reduce(
21
+ (acc, elt) => reduceByFunction(
22
+ valueFn, valueAcc, keyFn, acc, elt
23
+ ),
24
+ {},
25
+ list
26
+ )
27
+ }
28
+
29
+ export const reduceBy = curry(reduceByFn)
@@ -0,0 +1,27 @@
1
+ function sortHelper(
2
+ a, b, listOfSortingFns
3
+ ){
4
+ let result = 0
5
+ let i = 0
6
+ while (result === 0 && i < listOfSortingFns.length){
7
+ result = listOfSortingFns[ i ](a, b)
8
+ i += 1
9
+ }
10
+
11
+ return result
12
+ }
13
+
14
+ export function sortWith(listOfSortingFns, list){
15
+ if (arguments.length === 1)
16
+ return _list => sortWith(listOfSortingFns, _list)
17
+
18
+ if (Array.isArray(list) === false)
19
+ return []
20
+
21
+ const clone = list.slice()
22
+ clone.sort((a, b) => sortHelper(
23
+ a, b, listOfSortingFns
24
+ ))
25
+
26
+ return clone
27
+ }
package/src/values.js CHANGED
@@ -2,6 +2,5 @@ import { type } from './type.js'
2
2
 
3
3
  export function values(obj){
4
4
  if (type(obj) !== 'Object') return []
5
-
6
5
  return Object.values(obj)
7
- }
6
+ }