pepka 1.6.21 → 1.6.22

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 CHANGED
@@ -57,16 +57,7 @@ function curry2(fn) {
57
57
  }
58
58
  return curried2;
59
59
  }
60
- function curry3(fn) {
61
- // type p0 = Parameters<Func>[0]
62
- // type p1 = Parameters<Func>[1]
63
- // type p2 = Parameters<Func>[2]
64
- // type ReturnT = ReturnType<Func>
65
- // TODO: optimize.
66
- // Cannot use ts-toolbelt due to this error:
67
- // Excessive stack depth comparing types 'GapsOf<?, L2>' and 'GapsOf<?, L2>'
68
- return curry(fn);
69
- }
60
+ const curry3 = (fn) => curry(fn);
70
61
 
71
62
  const length = (s) => s.length;
72
63
  const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
@@ -257,9 +248,6 @@ const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), da
257
248
  // Aliases.
258
249
  const qpush = qappend;
259
250
 
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
251
  // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
264
252
  const take = (argN) => (...args) => args[argN];
265
253
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
@@ -277,6 +265,7 @@ const compose = ((...fns) => (...args) => {
277
265
  }
278
266
  return s;
279
267
  });
268
+ /** @param fn AnyFunc @param context any */
280
269
  const bind = curry2((fn, context) => fn.bind(context));
281
270
  const nth = curry2((i, data) => data[i]);
282
271
  // FIXME: these types. Somewhere in curry2.
@@ -433,11 +422,12 @@ const prop = curry2(((key, o) => o[key])); // as PropGetter
433
422
  const propEq = curry3((key, value, o) => equals(o[key], value));
434
423
  /** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
435
424
  const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
436
- const pathOr = curry3((_default, path, o) => length(path)
425
+ const _pathOr = (_default, path, o) => length(path)
437
426
  ? isNil(o)
438
427
  ? _default
439
- : compose((k) => k in o ? pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
440
- : o);
428
+ : compose((k) => k in o ? _pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
429
+ : o;
430
+ const pathOr = curry3(_pathOr); // it's more performant due to recursion there.
441
431
  const path = pathOr(undef);
442
432
  const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
443
433
  const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
@@ -556,6 +546,32 @@ const push = append;
556
546
  const some = any;
557
547
  const weakEq = eq;
558
548
 
549
+ /** One promise waits for another. */
550
+ const forEachSerial = (() => {
551
+ const pipe = async (fn, items, i) => {
552
+ if (i < items.length) {
553
+ await fn(items[i]);
554
+ await pipe(fn, items, ++i);
555
+ }
556
+ };
557
+ return curry2((fn, items) => pipe(fn, items, 0));
558
+ })();
559
+ /** Promise.all wrapper for functional pipelining. */
560
+ const waitAll = (promises) => Promise.all(promises);
561
+ /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
562
+ * @param {AnyFunc<Promise>} fn - function to wait.
563
+ * @param {T} s - any value to tap and return back
564
+ * @returns {T}
565
+ */
566
+ const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
567
+ /** Waits for all promises mapped by the fn. */
568
+ const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
569
+ /** The same as compose, but waits for promises in chains and returns a Promise. */
570
+ const composeAsync = (() => {
571
+ const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
572
+ return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
573
+ })();
574
+
559
575
  const ecran = '\\';
560
576
  // TODO: make it splicy, not accumulatie by symbols.
561
577
  /** Supports ecrans: '\\{"json": {yes} \\}'
@@ -623,44 +639,22 @@ const debounce = (time, fn) => {
623
639
  queue.push(ff);
624
640
  }));
625
641
  };
626
- // export const debouncePrepared =
627
642
  const throttle = (time, fn) => {
628
643
  let on = true;
644
+ let res;
629
645
  return (...args) => {
630
646
  if (on) {
631
647
  on = false;
632
648
  setTimeout(() => on = true, time);
633
- return fn(...args);
649
+ res = fn(...args);
634
650
  }
651
+ return res;
635
652
  };
636
653
  };
637
654
  const wait = (time) => new Promise((ff) => setTimeout(ff, time));
638
655
 
639
- /** One promise waits for another. */
640
- const forEachSerial = (() => {
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
- })();
656
+ // TODO: possibly introduce a second argument limiting unfolding.
657
+ const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
664
658
 
665
659
  exports.F = F;
666
660
  exports.T = T;
package/dist/bundle.mjs CHANGED
@@ -55,16 +55,7 @@ function curry2(fn) {
55
55
  }
56
56
  return curried2;
57
57
  }
58
- function curry3(fn) {
59
- // type p0 = Parameters<Func>[0]
60
- // type p1 = Parameters<Func>[1]
61
- // type p2 = Parameters<Func>[2]
62
- // type ReturnT = ReturnType<Func>
63
- // TODO: optimize.
64
- // Cannot use ts-toolbelt due to this error:
65
- // Excessive stack depth comparing types 'GapsOf<?, L2>' and 'GapsOf<?, L2>'
66
- return curry(fn);
67
- }
58
+ const curry3 = (fn) => curry(fn);
68
59
 
69
60
  const length = (s) => s.length;
70
61
  const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
@@ -255,9 +246,6 @@ const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), da
255
246
  // Aliases.
256
247
  const qpush = qappend;
257
248
 
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
249
  // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
262
250
  const take = (argN) => (...args) => args[argN];
263
251
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
@@ -275,6 +263,7 @@ const compose = ((...fns) => (...args) => {
275
263
  }
276
264
  return s;
277
265
  });
266
+ /** @param fn AnyFunc @param context any */
278
267
  const bind = curry2((fn, context) => fn.bind(context));
279
268
  const nth = curry2((i, data) => data[i]);
280
269
  // FIXME: these types. Somewhere in curry2.
@@ -431,11 +420,12 @@ const prop = curry2(((key, o) => o[key])); // as PropGetter
431
420
  const propEq = curry3((key, value, o) => equals(o[key], value));
432
421
  /** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
433
422
  const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
434
- const pathOr = curry3((_default, path, o) => length(path)
423
+ const _pathOr = (_default, path, o) => length(path)
435
424
  ? isNil(o)
436
425
  ? _default
437
- : compose((k) => k in o ? pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
438
- : o);
426
+ : compose((k) => k in o ? _pathOr(_default, slice(1, inf, path), o[k]) : _default, head)(path)
427
+ : o;
428
+ const pathOr = curry3(_pathOr); // it's more performant due to recursion there.
439
429
  const path = pathOr(undef);
440
430
  const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
441
431
  const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
@@ -554,6 +544,32 @@ const push = append;
554
544
  const some = any;
555
545
  const weakEq = eq;
556
546
 
547
+ /** One promise waits for another. */
548
+ const forEachSerial = (() => {
549
+ const pipe = async (fn, items, i) => {
550
+ if (i < items.length) {
551
+ await fn(items[i]);
552
+ await pipe(fn, items, ++i);
553
+ }
554
+ };
555
+ return curry2((fn, items) => pipe(fn, items, 0));
556
+ })();
557
+ /** Promise.all wrapper for functional pipelining. */
558
+ const waitAll = (promises) => Promise.all(promises);
559
+ /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
560
+ * @param {AnyFunc<Promise>} fn - function to wait.
561
+ * @param {T} s - any value to tap and return back
562
+ * @returns {T}
563
+ */
564
+ const waitTap = curry2(async (fn, s) => { await fn(s); return s; });
565
+ /** Waits for all promises mapped by the fn. */
566
+ const forEachAsync = curry2((fn, items) => Promise.all(items.map(fn)));
567
+ /** The same as compose, but waits for promises in chains and returns a Promise. */
568
+ const composeAsync = (() => {
569
+ const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
570
+ return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
571
+ })();
572
+
557
573
  const ecran = '\\';
558
574
  // TODO: make it splicy, not accumulatie by symbols.
559
575
  /** Supports ecrans: '\\{"json": {yes} \\}'
@@ -621,43 +637,21 @@ const debounce = (time, fn) => {
621
637
  queue.push(ff);
622
638
  }));
623
639
  };
624
- // export const debouncePrepared =
625
640
  const throttle = (time, fn) => {
626
641
  let on = true;
642
+ let res;
627
643
  return (...args) => {
628
644
  if (on) {
629
645
  on = false;
630
646
  setTimeout(() => on = true, time);
631
- return fn(...args);
647
+ res = fn(...args);
632
648
  }
649
+ return res;
633
650
  };
634
651
  };
635
652
  const wait = (time) => new Promise((ff) => setTimeout(ff, time));
636
653
 
637
- /** One promise waits for another. */
638
- const forEachSerial = (() => {
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
- })();
654
+ // TODO: possibly introduce a second argument limiting unfolding.
655
+ const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
662
656
 
663
657
  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.21",
44
+ "version": "1.6.22",
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
@@ -98,5 +98,5 @@ export type Curried3<A, B, C, R> =
98
98
  & ((a: Placeholder, b: B, c: Placeholder) => (a: A, c: C) => R)
99
99
  & ((a: A, b: Placeholder, c: Placeholder) => (b: B, c: C) => R)
100
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>
101
+ export const curry3 = <Params extends [any, any, any], ReturnT, F = AnyFunc<ReturnT, Params>>(fn: F):
102
+ Curried3<Params[0], Params[1], Params[2], ReturnT> => curry(fn as any)