rambda 8.5.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/CHANGELOG.md +14 -0
- package/README.md +189 -364
- package/dist/rambda.js +102 -20
- package/dist/rambda.umd.js +1 -1
- package/immutable.d.ts +104 -20
- package/index.d.ts +104 -20
- package/package.json +15 -15
- package/rambda.js +7 -0
- package/src/forEach.js +1 -26
- package/src/forEachObjIndexed.js +25 -0
- package/src/gt.js +6 -0
- package/src/gte.js +6 -0
- package/src/hasIn.js +9 -0
- package/src/innerJoin.js +41 -0
- package/src/prop.js +8 -4
- package/src/reduceBy.js +29 -0
- package/src/sortWith.js +27 -0
- package/src/values.js +1 -2
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
|
|
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;
|
|
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,
|
|
@@ -505,7 +512,8 @@ export function differenceWith<T1, T2>(
|
|
|
505
512
|
export function dissoc<T extends object, K extends keyof T>(prop: K, obj: T): Omit<T, K>;
|
|
506
513
|
export function dissoc<K extends string | number>(prop: K): <T extends object>(obj: T) => Omit<T, K>;
|
|
507
514
|
|
|
508
|
-
export function dissocPath<T>(
|
|
515
|
+
export function dissocPath<T>(path: Path, obj: any): T;
|
|
516
|
+
export function dissocPath<T>(path: Path): (obj: any) => T;
|
|
509
517
|
|
|
510
518
|
export function divide(x: number, y: number): number;
|
|
511
519
|
export function divide(x: number): (y: number) => number;
|
|
@@ -685,12 +693,19 @@ export function groupWith<T>(compareFn: (x: T, y: T) => boolean): (input: T[]) =
|
|
|
685
693
|
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: T[]): (T[])[];
|
|
686
694
|
export function groupWith<T>(compareFn: (x: T, y: T) => boolean, input: string): string[];
|
|
687
695
|
|
|
696
|
+
export function gt<T>(x: T): T;
|
|
697
|
+
|
|
698
|
+
export function gte<T>(x: T): T;
|
|
699
|
+
|
|
688
700
|
/**
|
|
689
701
|
* It returns `true` if `obj` has property `prop`.
|
|
690
702
|
*/
|
|
691
703
|
export function has<T>(prop: string, obj: T): boolean;
|
|
692
704
|
export function has(prop: string): <T>(obj: T) => boolean;
|
|
693
705
|
|
|
706
|
+
export function hasIn(searchProperty: string): <T>(obj: T) => boolean;
|
|
707
|
+
export function hasIn<T>(searchProperty: string, obj: T): boolean;
|
|
708
|
+
|
|
694
709
|
/**
|
|
695
710
|
* It will return true, if `input` object has truthy `path`(calculated with `R.path`).
|
|
696
711
|
*/
|
|
@@ -779,6 +794,18 @@ export function indexOf<T>(valueToFind: T): (list: T[]) => number;
|
|
|
779
794
|
export function init<T extends unknown[]>(input: T): T extends readonly [...infer U, any] ? U : [...T];
|
|
780
795
|
export function init(input: string): string;
|
|
781
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
|
+
|
|
782
809
|
/**
|
|
783
810
|
* It loops through `listA` and `listB` and returns the intersection of the two according to `R.equals`.
|
|
784
811
|
*/
|
|
@@ -862,26 +889,57 @@ export function length<T>(input: T[]): number;
|
|
|
862
889
|
*
|
|
863
890
|
* The setter should not mutate the data structure.
|
|
864
891
|
*/
|
|
865
|
-
export function lens<
|
|
892
|
+
export function lens<S, A>(getter: (s: S) => A, setter: (a: A, s: S) => S): Lens<S, A>;
|
|
866
893
|
|
|
867
894
|
/**
|
|
868
895
|
* It returns a lens that focuses on specified `index`.
|
|
869
896
|
*/
|
|
870
|
-
export function lensIndex(
|
|
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]>;
|
|
871
899
|
|
|
872
900
|
/**
|
|
873
901
|
* It returns a lens that focuses on specified `path`.
|
|
874
902
|
*/
|
|
875
|
-
export function lensPath(path:
|
|
876
|
-
export function lensPath
|
|
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>;
|
|
877
938
|
|
|
878
939
|
/**
|
|
879
940
|
* It returns a lens that focuses on specified property `prop`.
|
|
880
941
|
*/
|
|
881
|
-
export function lensProp(prop:
|
|
882
|
-
<T, U>(obj: T): U;
|
|
883
|
-
set<T, U, V>(val: T, obj: U): V;
|
|
884
|
-
};
|
|
942
|
+
export function lensProp<S, K extends keyof S = keyof S>(prop: K): Lens<S, S[K]>;
|
|
885
943
|
|
|
886
944
|
/**
|
|
887
945
|
* It returns the result of looping through `iterable` with `fn`.
|
|
@@ -1392,6 +1450,25 @@ export function reduce<T, TResult>(reducer: (prev: TResult, current: T) => TResu
|
|
|
1392
1450
|
export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult): (initialValue: TResult, list: T[]) => TResult;
|
|
1393
1451
|
export function reduce<T, TResult>(reducer: (prev: TResult, current: T, i: number) => TResult, initialValue: TResult): (list: T[]) => TResult;
|
|
1394
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
|
+
|
|
1395
1472
|
/**
|
|
1396
1473
|
* It has the opposite effect of `R.filter`.
|
|
1397
1474
|
*/
|
|
@@ -1453,6 +1530,9 @@ export function sortBy<T>(sortFn: (a: T) => Ord, list: T[]): T[];
|
|
|
1453
1530
|
export function sortBy<T>(sortFn: (a: T) => Ord): (list: T[]) => T[];
|
|
1454
1531
|
export function sortBy(sortFn: (a: any) => Ord): <T>(list: T[]) => T[];
|
|
1455
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
|
+
|
|
1456
1536
|
/**
|
|
1457
1537
|
* Curried version of `String.prototype.split`
|
|
1458
1538
|
*/
|
|
@@ -1683,9 +1763,13 @@ export function values<T extends object, K extends keyof T>(obj: T): T[K][];
|
|
|
1683
1763
|
/**
|
|
1684
1764
|
* It returns the value of `lens` focus over `target` object.
|
|
1685
1765
|
*/
|
|
1686
|
-
export function view<
|
|
1687
|
-
export function view<
|
|
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;
|
|
1688
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
|
+
*/
|
|
1689
1773
|
export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U, input: T): T | U;
|
|
1690
1774
|
export function when<T, U>(predicate: (x: T) => boolean, whenTrueFn: (a: T) => U): (input: T) => T | U;
|
|
1691
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": "
|
|
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",
|
|
@@ -38,30 +38,30 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@babel/core": "7.
|
|
41
|
+
"@babel/core": "7.23.3",
|
|
42
42
|
"@babel/plugin-proposal-object-rest-spread": "7.20.7",
|
|
43
|
-
"@babel/preset-env": "7.
|
|
43
|
+
"@babel/preset-env": "7.23.3",
|
|
44
44
|
"@definitelytyped/dtslint": "0.0.176",
|
|
45
|
-
"@rollup/plugin-babel": "6.0.
|
|
46
|
-
"@rollup/plugin-commonjs": "25.0.
|
|
47
|
-
"@rollup/plugin-node-resolve": "15.
|
|
48
|
-
"@rollup/plugin-replace": "5.0.
|
|
49
|
-
"@types/jest": "29.5.
|
|
45
|
+
"@rollup/plugin-babel": "6.0.4",
|
|
46
|
+
"@rollup/plugin-commonjs": "25.0.7",
|
|
47
|
+
"@rollup/plugin-node-resolve": "15.2.3",
|
|
48
|
+
"@rollup/plugin-replace": "5.0.5",
|
|
49
|
+
"@types/jest": "29.5.8",
|
|
50
50
|
"combinate": "1.1.11",
|
|
51
51
|
"cross-env": "7.0.3",
|
|
52
|
-
"fast-check": "
|
|
52
|
+
"fast-check": "3.13.2",
|
|
53
53
|
"helpers-fn": "1.8.1",
|
|
54
54
|
"is-ci": "3.0.1",
|
|
55
|
-
"jest": "29.
|
|
56
|
-
"jest-extended": "
|
|
55
|
+
"jest": "29.7.0",
|
|
56
|
+
"jest-extended": "4.0.2",
|
|
57
57
|
"lodash": "4.17.21",
|
|
58
|
-
"rambdax": "
|
|
59
|
-
"ramda": "0.29.
|
|
60
|
-
"rollup": "
|
|
58
|
+
"rambdax": "10.0.0",
|
|
59
|
+
"ramda": "0.29.1",
|
|
60
|
+
"rollup": "4.4.1",
|
|
61
61
|
"rollup-plugin-cleanup": "3.2.1",
|
|
62
62
|
"rollup-plugin-sourcemaps": "0.6.3",
|
|
63
63
|
"rollup-plugin-uglify": "6.0.4",
|
|
64
|
-
"types-ramda": "0.29.
|
|
64
|
+
"types-ramda": "0.29.6",
|
|
65
65
|
"typescript": "5.2.2"
|
|
66
66
|
},
|
|
67
67
|
"jest": {
|
package/rambda.js
CHANGED
|
@@ -69,10 +69,14 @@ export * from './src/findLastIndex.js'
|
|
|
69
69
|
export * from './src/flatten.js'
|
|
70
70
|
export * from './src/flip.js'
|
|
71
71
|
export * from './src/forEach.js'
|
|
72
|
+
export * from './src/forEachObjIndexed.js'
|
|
72
73
|
export * from './src/fromPairs.js'
|
|
73
74
|
export * from './src/groupBy.js'
|
|
74
75
|
export * from './src/groupWith.js'
|
|
76
|
+
export * from './src/gt.js'
|
|
77
|
+
export * from './src/gte.js'
|
|
75
78
|
export * from './src/has.js'
|
|
79
|
+
export * from './src/hasIn.js'
|
|
76
80
|
export * from './src/hasPath.js'
|
|
77
81
|
export * from './src/head.js'
|
|
78
82
|
export * from './src/identical.js'
|
|
@@ -83,6 +87,7 @@ export * from './src/includes.js'
|
|
|
83
87
|
export * from './src/indexBy.js'
|
|
84
88
|
export * from './src/indexOf.js'
|
|
85
89
|
export * from './src/init.js'
|
|
90
|
+
export * from './src/innerJoin.js'
|
|
86
91
|
export * from './src/intersection.js'
|
|
87
92
|
export * from './src/intersperse.js'
|
|
88
93
|
export * from './src/is.js'
|
|
@@ -150,6 +155,7 @@ export * from './src/propSatisfies.js'
|
|
|
150
155
|
export * from './src/props.js'
|
|
151
156
|
export * from './src/range.js'
|
|
152
157
|
export * from './src/reduce.js'
|
|
158
|
+
export * from './src/reduceBy.js'
|
|
153
159
|
export * from './src/reject.js'
|
|
154
160
|
export * from './src/removeIndex.js'
|
|
155
161
|
export * from './src/repeat.js'
|
|
@@ -159,6 +165,7 @@ export * from './src/set.js'
|
|
|
159
165
|
export * from './src/slice.js'
|
|
160
166
|
export * from './src/sort.js'
|
|
161
167
|
export * from './src/sortBy.js'
|
|
168
|
+
export * from './src/sortWith.js'
|
|
162
169
|
export * from './src/split.js'
|
|
163
170
|
export * from './src/splitAt.js'
|
|
164
171
|
export * from './src/splitEvery.js'
|
package/src/forEach.js
CHANGED
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
import { isArray } from './_internals/isArray.js'
|
|
2
|
-
import {
|
|
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
package/src/gte.js
ADDED
package/src/hasIn.js
ADDED
package/src/innerJoin.js
ADDED
|
@@ -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
|
|
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[
|
|
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
|
}
|
package/src/reduceBy.js
ADDED
|
@@ -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)
|
package/src/sortWith.js
ADDED
|
@@ -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
|
+
}
|