pepka 1.6.21 → 1.6.23
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/bundle.cjs +36 -33
- package/dist/bundle.d.ts +30 -40
- package/dist/bundle.mjs +36 -33
- package/package.json +1 -1
- package/src/curry.ts +11 -13
- package/src/safe.ts +1 -1
package/dist/bundle.cjs
CHANGED
|
@@ -257,9 +257,6 @@ const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), da
|
|
|
257
257
|
// Aliases.
|
|
258
258
|
const qpush = qappend;
|
|
259
259
|
|
|
260
|
-
// TODO: possibly introduce a second argument limiting unfolding.
|
|
261
|
-
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
262
|
-
|
|
263
260
|
// TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
264
261
|
const take = (argN) => (...args) => args[argN];
|
|
265
262
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
@@ -277,6 +274,7 @@ const compose = ((...fns) => (...args) => {
|
|
|
277
274
|
}
|
|
278
275
|
return s;
|
|
279
276
|
});
|
|
277
|
+
/** @param fn AnyFunc @param context any */
|
|
280
278
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
281
279
|
const nth = curry2((i, data) => data[i]);
|
|
282
280
|
// FIXME: these types. Somewhere in curry2.
|
|
@@ -433,11 +431,12 @@ const prop = curry2(((key, o) => o[key])); // as PropGetter
|
|
|
433
431
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
434
432
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
435
433
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
436
|
-
const
|
|
434
|
+
const _pathOr = (_default, path, o) => length(path)
|
|
437
435
|
? isNil(o)
|
|
438
436
|
? _default
|
|
439
|
-
: compose((k) => k in o ?
|
|
440
|
-
: o
|
|
437
|
+
: compose((k) => k in o ? _pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
|
|
438
|
+
: o;
|
|
439
|
+
const pathOr = curry3(_pathOr); // it's more performant due to recursion there.
|
|
441
440
|
const path = pathOr(undef);
|
|
442
441
|
const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
|
|
443
442
|
const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
|
|
@@ -556,6 +555,32 @@ const push = append;
|
|
|
556
555
|
const some = any;
|
|
557
556
|
const weakEq = eq;
|
|
558
557
|
|
|
558
|
+
/** One promise waits for another. */
|
|
559
|
+
const forEachSerial = (() => {
|
|
560
|
+
const pipe = async (fn, items, i) => {
|
|
561
|
+
if (i < items.length) {
|
|
562
|
+
await fn(items[i]);
|
|
563
|
+
await pipe(fn, items, ++i);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
return curry2((fn, items) => pipe(fn, items, 0));
|
|
567
|
+
})();
|
|
568
|
+
/** Promise.all wrapper for functional pipelining. */
|
|
569
|
+
const waitAll = (promises) => Promise.all(promises);
|
|
570
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
571
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
572
|
+
* @param {T} s - any value to tap and return back
|
|
573
|
+
* @returns {T}
|
|
574
|
+
*/
|
|
575
|
+
const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
|
|
576
|
+
/** Waits for all promises mapped by the fn. */
|
|
577
|
+
const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
|
|
578
|
+
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
579
|
+
const composeAsync = (() => {
|
|
580
|
+
const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
|
|
581
|
+
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
582
|
+
})();
|
|
583
|
+
|
|
559
584
|
const ecran = '\\';
|
|
560
585
|
// TODO: make it splicy, not accumulatie by symbols.
|
|
561
586
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
@@ -623,44 +648,22 @@ const debounce = (time, fn) => {
|
|
|
623
648
|
queue.push(ff);
|
|
624
649
|
}));
|
|
625
650
|
};
|
|
626
|
-
// export const debouncePrepared =
|
|
627
651
|
const throttle = (time, fn) => {
|
|
628
652
|
let on = true;
|
|
653
|
+
let res;
|
|
629
654
|
return (...args) => {
|
|
630
655
|
if (on) {
|
|
631
656
|
on = false;
|
|
632
657
|
setTimeout(() => on = true, time);
|
|
633
|
-
|
|
658
|
+
res = fn(...args);
|
|
634
659
|
}
|
|
660
|
+
return res;
|
|
635
661
|
};
|
|
636
662
|
};
|
|
637
663
|
const wait = (time) => new Promise((ff) => setTimeout(ff, time));
|
|
638
664
|
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
const pipe = async (fn, items, i) => {
|
|
642
|
-
if (i < items.length) {
|
|
643
|
-
await fn(items[i]);
|
|
644
|
-
await pipe(fn, items, ++i);
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
return curry2((fn, items) => pipe(fn, items, 0));
|
|
648
|
-
})();
|
|
649
|
-
/** Promise.all wrapper for functional pipelining. */
|
|
650
|
-
const waitAll = (promises) => Promise.all(promises);
|
|
651
|
-
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
652
|
-
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
653
|
-
* @param {T} s - any value to tap and return back
|
|
654
|
-
* @returns {T}
|
|
655
|
-
*/
|
|
656
|
-
const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
|
|
657
|
-
/** Waits for all promises mapped by the fn. */
|
|
658
|
-
const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
|
|
659
|
-
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
660
|
-
const composeAsync = (() => {
|
|
661
|
-
const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
|
|
662
|
-
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
663
|
-
})();
|
|
665
|
+
// TODO: possibly introduce a second argument limiting unfolding.
|
|
666
|
+
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
664
667
|
|
|
665
668
|
exports.F = F;
|
|
666
669
|
exports.T = T;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -30,12 +30,6 @@ export type PathValue<O, Keys extends readonly PropertyKey[], Default> = Keys ex
|
|
|
30
30
|
type Placeholder = symbol;
|
|
31
31
|
export declare const __: Placeholder;
|
|
32
32
|
export declare const curry: (fn: AnyFunc) => (...args: AnyArgs) => any;
|
|
33
|
-
type Curried2<p0, p1, ReturnT> = {
|
|
34
|
-
(a: Placeholder, b: p1): (a: p0) => ReturnT;
|
|
35
|
-
(a: p0, b: Placeholder): (b: p1) => ReturnT;
|
|
36
|
-
(a: p0): (b: p1) => ReturnT;
|
|
37
|
-
(a: p0, b: p1): ReturnT;
|
|
38
|
-
};
|
|
39
33
|
type Func2 = (a: any, b: any) => any;
|
|
40
34
|
export declare function curry2<Func extends Func2>(fn: Func): {
|
|
41
35
|
(a: Placeholder, b: Parameters<Func>[1]): (a: Parameters<Func>[0]) => ReturnType<Func>;
|
|
@@ -43,12 +37,8 @@ export declare function curry2<Func extends Func2>(fn: Func): {
|
|
|
43
37
|
(a: Parameters<Func>[0]): (b: Parameters<Func>[1]) => ReturnType<Func>;
|
|
44
38
|
(a: Parameters<Func>[0], b: Parameters<Func>[1]): ReturnType<Func>;
|
|
45
39
|
};
|
|
46
|
-
type
|
|
47
|
-
export declare
|
|
48
|
-
any,
|
|
49
|
-
any,
|
|
50
|
-
any
|
|
51
|
-
], ReturnT, F = AnyFunc<ReturnT, Params>>(fn: F) => Curried3<Params[0], Params[1], Params[2], ReturnT>;
|
|
40
|
+
type Func3 = (a: any, b: any, c: any) => any;
|
|
41
|
+
export declare function curry3<Func extends Func3>(fn: Func): (...args: AnyArgs) => any;
|
|
52
42
|
/** One promise waits for another. */
|
|
53
43
|
export declare const forEachSerial: {
|
|
54
44
|
(a: Placeholder, b: any[]): (a: AnyFunc) => Promise<void>;
|
|
@@ -113,8 +103,8 @@ export declare const qappend: {
|
|
|
113
103
|
(a: any): (b: any[]) => any[];
|
|
114
104
|
(a: any, b: any[]): any[];
|
|
115
105
|
};
|
|
116
|
-
export declare const qassoc:
|
|
117
|
-
export declare const qreduce:
|
|
106
|
+
export declare const qassoc: (...args: AnyArgs) => any;
|
|
107
|
+
export declare const qreduce: (...args: AnyArgs) => any;
|
|
118
108
|
export declare const qmergeDeep: {
|
|
119
109
|
(a: Placeholder, b: AnyObject): (a: AnyObject) => AnyObject;
|
|
120
110
|
(a: AnyObject, b: Placeholder): (b: AnyObject) => AnyObject;
|
|
@@ -189,7 +179,7 @@ export declare const qsort: {
|
|
|
189
179
|
(a: (a: any, b: any) => number): (b: any[]) => any[];
|
|
190
180
|
(a: (a: any, b: any) => number, b: any[]): any[];
|
|
191
181
|
};
|
|
192
|
-
export declare const qassocPath:
|
|
182
|
+
export declare const qassocPath: (...args: AnyArgs) => any;
|
|
193
183
|
export declare const qreverse: (arr: any[]) => any[];
|
|
194
184
|
export declare const qomit: {
|
|
195
185
|
(a: Placeholder, b: AnyObject): (a: string[]) => any[] | AnyObject;
|
|
@@ -199,7 +189,7 @@ export declare const qomit: {
|
|
|
199
189
|
};
|
|
200
190
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
201
191
|
* @returns data with prop over pipe. */
|
|
202
|
-
export declare const qoverProp:
|
|
192
|
+
export declare const qoverProp: (...args: AnyArgs) => any;
|
|
203
193
|
export declare const qpush: {
|
|
204
194
|
(a: Placeholder, b: any[]): (a: any) => any[];
|
|
205
195
|
(a: any, b: Placeholder): (b: any[]) => any[];
|
|
@@ -209,7 +199,7 @@ export declare const qpush: {
|
|
|
209
199
|
export declare const isNil: <T extends any>(s: T) => T extends (null | undefined) ? true : false;
|
|
210
200
|
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
211
201
|
export declare const ifElse: (...args: AnyArgs) => any;
|
|
212
|
-
export declare const when:
|
|
202
|
+
export declare const when: (...args: AnyArgs) => any;
|
|
213
203
|
export declare const compose: <TIn extends any[] = any[], TOut = any>(...fns: AnyFunc[]) => Composed<TIn, TOut>;
|
|
214
204
|
/** @param fn AnyFunc @param context any */
|
|
215
205
|
export declare const bind: {
|
|
@@ -224,7 +214,7 @@ export declare const nth: {
|
|
|
224
214
|
(a: number): (b: string | ArrayLike<unknown>) => unknown;
|
|
225
215
|
(a: number, b: string | ArrayLike<unknown>): unknown;
|
|
226
216
|
};
|
|
227
|
-
export declare const slice:
|
|
217
|
+
export declare const slice: (...args: AnyArgs) => any;
|
|
228
218
|
export declare const flip: <T extends AnyFunc>(fn: T) => {
|
|
229
219
|
(a: Placeholder, b: Parameters<T>[0]): (a: Parameters<T>[1]) => any;
|
|
230
220
|
(a: Parameters<T>[1], b: Placeholder): (b: Parameters<T>[0]) => any;
|
|
@@ -433,13 +423,13 @@ export declare const range: {
|
|
|
433
423
|
};
|
|
434
424
|
/** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
|
|
435
425
|
export declare const uniqWith: {
|
|
436
|
-
(a: Placeholder, b: any[]): (a: (x: any, y: any) => boolean) =>
|
|
437
|
-
(a: (x: any, y: any) => boolean, b: Placeholder): (b: any[]) =>
|
|
438
|
-
(a: (x: any, y: any) => boolean): (b: any[]) =>
|
|
439
|
-
(a: (x: any, y: any) => boolean, b: any[]):
|
|
426
|
+
(a: Placeholder, b: any[]): (a: (x: any, y: any) => boolean) => any;
|
|
427
|
+
(a: (x: any, y: any) => boolean, b: Placeholder): (b: any[]) => any;
|
|
428
|
+
(a: (x: any, y: any) => boolean): (b: any[]) => any;
|
|
429
|
+
(a: (x: any, y: any) => boolean, b: any[]): any;
|
|
440
430
|
};
|
|
441
431
|
/** @param xs any[] @returns xs without duplicates. */
|
|
442
|
-
export declare const uniq: (b: any[]) =>
|
|
432
|
+
export declare const uniq: (b: any[]) => any;
|
|
443
433
|
export declare const intersection: {
|
|
444
434
|
(a: Placeholder, b: any[]): (a: any[]) => any[];
|
|
445
435
|
(a: any[], b: Placeholder): (b: any[]) => any[];
|
|
@@ -487,8 +477,8 @@ export declare const cond: {
|
|
|
487
477
|
* @param value any
|
|
488
478
|
* @param object AnyObject
|
|
489
479
|
*/
|
|
490
|
-
export declare const assoc:
|
|
491
|
-
export declare const assocPath:
|
|
480
|
+
export declare const assoc: (...args: AnyArgs) => any;
|
|
481
|
+
export declare const assocPath: (...args: AnyArgs) => any;
|
|
492
482
|
export declare const all: {
|
|
493
483
|
(a: Placeholder, b: any[]): (a: Cond) => boolean;
|
|
494
484
|
(a: Cond, b: Placeholder): (b: any[]) => boolean;
|
|
@@ -535,13 +525,13 @@ export declare const prop: {
|
|
|
535
525
|
(a: string, b: AnyObject): any;
|
|
536
526
|
};
|
|
537
527
|
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
538
|
-
export declare const propEq:
|
|
528
|
+
export declare const propEq: (...args: AnyArgs) => any;
|
|
539
529
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
540
|
-
export declare const propsEq:
|
|
541
|
-
export declare const pathOr:
|
|
542
|
-
export declare const path:
|
|
543
|
-
export declare const pathEq:
|
|
544
|
-
export declare const pathsEq:
|
|
530
|
+
export declare const propsEq: (...args: AnyArgs) => any;
|
|
531
|
+
export declare const pathOr: (...args: AnyArgs) => any;
|
|
532
|
+
export declare const path: any;
|
|
533
|
+
export declare const pathEq: (...args: AnyArgs) => any;
|
|
534
|
+
export declare const pathsEq: (...args: AnyArgs) => any;
|
|
545
535
|
export declare const pathExists: Composed<any[], any>;
|
|
546
536
|
export declare const clone: <T extends any>(s: T, shallow?: boolean) => T;
|
|
547
537
|
export declare const cloneShallow: (s: any) => any;
|
|
@@ -552,7 +542,7 @@ export declare const freezeShallow: <T extends AnyObject>(o: T) => Readonly<T>;
|
|
|
552
542
|
* @param accum T1
|
|
553
543
|
* @param array T2[]
|
|
554
544
|
*/
|
|
555
|
-
export declare const reduce:
|
|
545
|
+
export declare const reduce: (...args: AnyArgs) => any;
|
|
556
546
|
export declare const pick: {
|
|
557
547
|
(a: Placeholder, b: AnyObject): (a: string[]) => {};
|
|
558
548
|
(a: string[], b: Placeholder): (b: AnyObject) => {};
|
|
@@ -623,10 +613,10 @@ export declare const forEach: {
|
|
|
623
613
|
(a: (s: unknown, i: number, arr: unknown[]) => any): (b: any[]) => void;
|
|
624
614
|
(a: (s: unknown, i: number, arr: unknown[]) => any, b: any[]): void;
|
|
625
615
|
};
|
|
626
|
-
export declare const both:
|
|
616
|
+
export declare const both: (...args: AnyArgs) => any;
|
|
627
617
|
export declare const isEmpty: (s: any) => boolean | null;
|
|
628
618
|
export declare const empty: (s: any) => {} | undefined;
|
|
629
|
-
export declare const replace:
|
|
619
|
+
export declare const replace: (...args: AnyArgs) => any;
|
|
630
620
|
export declare const filter: {
|
|
631
621
|
(a: Placeholder, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any;
|
|
632
622
|
(a: (v: any, k: string | number) => boolean, b: Placeholder): (b: any[] | AnyObject) => any;
|
|
@@ -668,7 +658,7 @@ export declare const mergeDeepAdd: {
|
|
|
668
658
|
(a: AnyObject, b: AnyObject): AnyObject;
|
|
669
659
|
};
|
|
670
660
|
/** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
|
|
671
|
-
export declare const overProp:
|
|
661
|
+
export declare const overProp: (...args: AnyArgs) => any;
|
|
672
662
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
673
663
|
export declare const mapKeys: {
|
|
674
664
|
(a: Placeholder, b: AnyObject): (a: {
|
|
@@ -691,10 +681,10 @@ export declare const zip: {
|
|
|
691
681
|
(a: unknown[], b: unknown[]): any[];
|
|
692
682
|
};
|
|
693
683
|
export declare const zipObj: {
|
|
694
|
-
(a: Placeholder, b: unknown[]): (a: unknown[]) =>
|
|
695
|
-
(a: unknown[], b: Placeholder): (b: unknown[]) =>
|
|
696
|
-
(a: unknown[]): (b: unknown[]) =>
|
|
697
|
-
(a: unknown[], b: unknown[]):
|
|
684
|
+
(a: Placeholder, b: unknown[]): (a: unknown[]) => any;
|
|
685
|
+
(a: unknown[], b: Placeholder): (b: unknown[]) => any;
|
|
686
|
+
(a: unknown[]): (b: unknown[]) => any;
|
|
687
|
+
(a: unknown[], b: unknown[]): any;
|
|
698
688
|
};
|
|
699
689
|
/** zips through a pipe. Types T1, T2, T3.
|
|
700
690
|
* @returns T3[]
|
|
@@ -702,7 +692,7 @@ export declare const zipObj: {
|
|
|
702
692
|
* @param a T1[]
|
|
703
693
|
* @param b T2[]
|
|
704
694
|
*/
|
|
705
|
-
export declare const zipWith:
|
|
695
|
+
export declare const zipWith: (...args: AnyArgs) => any;
|
|
706
696
|
export declare const mirror: <T extends unknown>(s: T) => T;
|
|
707
697
|
export declare const reflect: <T extends unknown>(s: T) => T;
|
|
708
698
|
export declare const echo: <T extends unknown>(s: T) => T;
|
package/dist/bundle.mjs
CHANGED
|
@@ -255,9 +255,6 @@ const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), da
|
|
|
255
255
|
// Aliases.
|
|
256
256
|
const qpush = qappend;
|
|
257
257
|
|
|
258
|
-
// TODO: possibly introduce a second argument limiting unfolding.
|
|
259
|
-
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
260
|
-
|
|
261
258
|
// TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
262
259
|
const take = (argN) => (...args) => args[argN];
|
|
263
260
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
@@ -275,6 +272,7 @@ const compose = ((...fns) => (...args) => {
|
|
|
275
272
|
}
|
|
276
273
|
return s;
|
|
277
274
|
});
|
|
275
|
+
/** @param fn AnyFunc @param context any */
|
|
278
276
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
279
277
|
const nth = curry2((i, data) => data[i]);
|
|
280
278
|
// FIXME: these types. Somewhere in curry2.
|
|
@@ -431,11 +429,12 @@ const prop = curry2(((key, o) => o[key])); // as PropGetter
|
|
|
431
429
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
432
430
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
433
431
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
434
|
-
const
|
|
432
|
+
const _pathOr = (_default, path, o) => length(path)
|
|
435
433
|
? isNil(o)
|
|
436
434
|
? _default
|
|
437
|
-
: compose((k) => k in o ?
|
|
438
|
-
: o
|
|
435
|
+
: compose((k) => k in o ? _pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
|
|
436
|
+
: o;
|
|
437
|
+
const pathOr = curry3(_pathOr); // it's more performant due to recursion there.
|
|
439
438
|
const path = pathOr(undef);
|
|
440
439
|
const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
|
|
441
440
|
const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
|
|
@@ -554,6 +553,32 @@ const push = append;
|
|
|
554
553
|
const some = any;
|
|
555
554
|
const weakEq = eq;
|
|
556
555
|
|
|
556
|
+
/** One promise waits for another. */
|
|
557
|
+
const forEachSerial = (() => {
|
|
558
|
+
const pipe = async (fn, items, i) => {
|
|
559
|
+
if (i < items.length) {
|
|
560
|
+
await fn(items[i]);
|
|
561
|
+
await pipe(fn, items, ++i);
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
return curry2((fn, items) => pipe(fn, items, 0));
|
|
565
|
+
})();
|
|
566
|
+
/** Promise.all wrapper for functional pipelining. */
|
|
567
|
+
const waitAll = (promises) => Promise.all(promises);
|
|
568
|
+
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
569
|
+
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
570
|
+
* @param {T} s - any value to tap and return back
|
|
571
|
+
* @returns {T}
|
|
572
|
+
*/
|
|
573
|
+
const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
|
|
574
|
+
/** Waits for all promises mapped by the fn. */
|
|
575
|
+
const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
|
|
576
|
+
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
577
|
+
const composeAsync = (() => {
|
|
578
|
+
const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
|
|
579
|
+
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
580
|
+
})();
|
|
581
|
+
|
|
557
582
|
const ecran = '\\';
|
|
558
583
|
// TODO: make it splicy, not accumulatie by symbols.
|
|
559
584
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
@@ -621,43 +646,21 @@ const debounce = (time, fn) => {
|
|
|
621
646
|
queue.push(ff);
|
|
622
647
|
}));
|
|
623
648
|
};
|
|
624
|
-
// export const debouncePrepared =
|
|
625
649
|
const throttle = (time, fn) => {
|
|
626
650
|
let on = true;
|
|
651
|
+
let res;
|
|
627
652
|
return (...args) => {
|
|
628
653
|
if (on) {
|
|
629
654
|
on = false;
|
|
630
655
|
setTimeout(() => on = true, time);
|
|
631
|
-
|
|
656
|
+
res = fn(...args);
|
|
632
657
|
}
|
|
658
|
+
return res;
|
|
633
659
|
};
|
|
634
660
|
};
|
|
635
661
|
const wait = (time) => new Promise((ff) => setTimeout(ff, time));
|
|
636
662
|
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
const pipe = async (fn, items, i) => {
|
|
640
|
-
if (i < items.length) {
|
|
641
|
-
await fn(items[i]);
|
|
642
|
-
await pipe(fn, items, ++i);
|
|
643
|
-
}
|
|
644
|
-
};
|
|
645
|
-
return curry2((fn, items) => pipe(fn, items, 0));
|
|
646
|
-
})();
|
|
647
|
-
/** Promise.all wrapper for functional pipelining. */
|
|
648
|
-
const waitAll = (promises) => Promise.all(promises);
|
|
649
|
-
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
650
|
-
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
651
|
-
* @param {T} s - any value to tap and return back
|
|
652
|
-
* @returns {T}
|
|
653
|
-
*/
|
|
654
|
-
const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
|
|
655
|
-
/** Waits for all promises mapped by the fn. */
|
|
656
|
-
const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
|
|
657
|
-
/** The same as compose, but waits for promises in chains and returns a Promise. */
|
|
658
|
-
const composeAsync = (() => {
|
|
659
|
-
const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
|
|
660
|
-
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
661
|
-
})();
|
|
663
|
+
// TODO: possibly introduce a second argument limiting unfolding.
|
|
664
|
+
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
662
665
|
|
|
663
666
|
export { F, T, __, add, all, allPass, always, any, anyPass, append, assoc, assocPath, bind, both, callFrom, callWith, clone, cloneShallow, complement, compose, composeAsync, concat, cond, curry, curry2, curry3, debounce, diff, divide, echo, empty, eq, equals, explore, filter, find, findIndex, flat, flatShallow, flatTo, flip, forEach, forEachAsync, forEachSerial, freeze, freezeShallow, fromPairs, genBy, getTmpl, gt, gte, head, identity, ifElse, includes, indexOf, intersection, isEmpty, isNil, join, keys, last, length, lt, lte, map, mapKeys, mapObj, memoize, mergeDeep, mergeDeepAdd, mergeDeepX, mergeShallow, mirror, multiply, noop, not, notf, nth, omit, once, overProp, path, pathEq, pathExists, pathOr, pathsEq, pick, pickBy, prepend, prop, propEq, propsEq, push, qappend, qassoc, qassocPath, qempty, qfilter, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qprepend, qpush, qreduce, qreverse, qsort, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, startsWithShallow, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
package/package.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
42
|
"all": "npm run dev && npm run prod"
|
|
43
43
|
},
|
|
44
|
-
"version": "1.6.
|
|
44
|
+
"version": "1.6.23",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/curry.ts
CHANGED
|
@@ -87,16 +87,14 @@ export function curry2<Func extends Func2>(fn: Func) {
|
|
|
87
87
|
return curried2
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
export declare const curry3: <Params extends [any, any, any], ReturnT, F = AnyFunc<ReturnT, Params>>(fn: F) =>
|
|
102
|
-
Curried3<Params[0], Params[1], Params[2], ReturnT>
|
|
90
|
+
type Func3 = (a: any, b: any, c: any) => any
|
|
91
|
+
export function curry3<Func extends Func3>(fn: Func) {
|
|
92
|
+
// type p0 = Parameters<Func>[0]
|
|
93
|
+
// type p1 = Parameters<Func>[1]
|
|
94
|
+
// type p2 = Parameters<Func>[2]
|
|
95
|
+
// type ReturnT = ReturnType<Func>
|
|
96
|
+
// TODO: optimize.
|
|
97
|
+
// Cannot use ts-toolbelt due to this error:
|
|
98
|
+
// Excessive stack depth comparing types 'GapsOf<?, L2>' and 'GapsOf<?, L2>'
|
|
99
|
+
return curry(fn)
|
|
100
|
+
}
|
package/src/safe.ts
CHANGED
|
@@ -274,7 +274,7 @@ const _pathOr = (_default: any, path: (string | number)[], o: AnyObject) => leng
|
|
|
274
274
|
head
|
|
275
275
|
)(path)
|
|
276
276
|
: o
|
|
277
|
-
export const pathOr = curry3
|
|
277
|
+
export const pathOr = curry3(_pathOr) // it's more performant due to recursion there.
|
|
278
278
|
export const path = pathOr(undef)
|
|
279
279
|
export const pathEq = curry3(
|
|
280
280
|
(_path: string[], value: any, o: AnyObject) => equals(path(_path, o), value)
|