pepka 1.3.1 → 1.4.2

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
@@ -136,7 +136,10 @@ const qstartsWithWith = (comparator) => curry2((start, s) => {
136
136
  return true;
137
137
  });
138
138
 
139
- // TODO: qflat, qoverProp, qover array ?
139
+ // TODO: qoverProp, qover array ?
140
+ /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
141
+ * qflat, qpick
142
+ */
140
143
  const qappend = curry2((s, xs) => { xs.push(s); return xs; });
141
144
  const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
142
145
  const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
@@ -278,15 +281,15 @@ const tail = slice(1, inf);
278
281
  const add = curry2((a, b) => a + b);
279
282
  /** @param a @param b @returns b-a */
280
283
  const subtract = curry2((a, b) => b - a);
281
- /**@param a @param b @returns a*b */
284
+ /**@param a @param b @returns a×b */
282
285
  const multiply = curry2((a, b) => a * b);
283
286
  /** @param a @param b @returns a<b */
284
287
  const gt = curry2((a, b) => a < b);
285
288
  /** @param a @param b @returns a>b */
286
289
  const lt = curry2((a, b) => a > b);
287
- /** @param a @param b @returns a<=b */
290
+ /** @param a @param b @returns ab */
288
291
  const gte = curry2((a, b) => a <= b);
289
- /** @param a @param b @returns a>=b */
292
+ /** @param a @param b @returns ab */
290
293
  const lte = curry2((a, b) => a >= b);
291
294
  const sort = curry2((sortFn, xs) => xs.sort(sortFn));
292
295
  const find = curry2((fn, s) => s.find(fn));
@@ -316,9 +319,9 @@ const F = always(false);
316
319
  const callWith = curry2((args, fn) => fn(...args));
317
320
  const noop = (() => { });
318
321
  /** Calls a func from object.
319
- * @param {any[]} [args] - arguments for the function.
320
- * @param {string} [fnName] - property name of the function.
321
- * @param {AnyObject} [o] - the object with the function. */
322
+ * @param {any[]} args - arguments for the function.
323
+ * @param {string} fnName - property name of the function.
324
+ * @param {AnyObject} o - the object with the function. */
322
325
  const callFrom = curry((args, fn, o) => o[fn](...args));
323
326
  const complement = (fn) => (...args) => {
324
327
  const out = fn(...args);
@@ -339,6 +342,29 @@ const range = curry2((from, to) => genBy(add(from), to - from));
339
342
  /** @param xs any[] @returns xs without duplicates. */
340
343
  const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
341
344
  const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
345
+ const diff = curry2((_xs1, _xs2) => {
346
+ const len1 = length(_xs1);
347
+ const len2 = length(_xs2); // xs2 should be shorter 4 Set mem consumption.
348
+ const xs1 = len1 > len2 ? _xs1 : _xs2;
349
+ const xs2 = len1 > len2 ? _xs2 : _xs1;
350
+ const xset2 = new Set(xs2);
351
+ const common = new Set();
352
+ const out = [];
353
+ let i;
354
+ for (i = 0; i < len1; i++) {
355
+ const el = xs1[i];
356
+ if (xset2.has(el))
357
+ common.add(el);
358
+ else
359
+ out.push(el);
360
+ }
361
+ for (i = 0; i < len2; i++) {
362
+ const el = xs2[i];
363
+ if (!common.has(el))
364
+ out.push(el);
365
+ }
366
+ return out;
367
+ });
342
368
  const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
343
369
  const once = (fn) => {
344
370
  let done = false, cache;
@@ -592,6 +618,7 @@ exports.cond = cond;
592
618
  exports.curry = curry;
593
619
  exports.curry2 = curry2;
594
620
  exports.curry3 = curry3;
621
+ exports.diff = diff;
595
622
  exports.divide = divide;
596
623
  exports.echo = echo;
597
624
  exports.empty = empty;
package/dist/bundle.d.ts CHANGED
@@ -108,7 +108,7 @@ export declare const subtract: {
108
108
  (a: number): (b: number) => number;
109
109
  (a: number, b: number): number;
110
110
  };
111
- /**@param a @param b @returns a*b */
111
+ /**@param a @param b @returns a×b */
112
112
  export declare const multiply: {
113
113
  (a: symbol, b: number): (a: number) => number;
114
114
  (a: number, b: symbol): (b: number) => number;
@@ -129,14 +129,14 @@ export declare const lt: {
129
129
  (a: number): (b: number) => boolean;
130
130
  (a: number, b: number): boolean;
131
131
  };
132
- /** @param a @param b @returns a<=b */
132
+ /** @param a @param b @returns ab */
133
133
  export declare const gte: {
134
134
  (a: symbol, b: number): (a: number) => boolean;
135
135
  (a: number, b: symbol): (b: number) => boolean;
136
136
  (a: number): (b: number) => boolean;
137
137
  (a: number, b: number): boolean;
138
138
  };
139
- /** @param a @param b @returns a>=b */
139
+ /** @param a @param b @returns ab */
140
140
  export declare const lte: {
141
141
  (a: symbol, b: number): (a: number) => boolean;
142
142
  (a: number, b: symbol): (b: number) => boolean;
@@ -251,9 +251,9 @@ export declare const callWith: {
251
251
  };
252
252
  export declare const noop: (...args: any[]) => any;
253
253
  /** Calls a func from object.
254
- * @param {any[]} [args] - arguments for the function.
255
- * @param {string} [fnName] - property name of the function.
256
- * @param {AnyObject} [o] - the object with the function. */
254
+ * @param {any[]} args - arguments for the function.
255
+ * @param {string} fnName - property name of the function.
256
+ * @param {AnyObject} o - the object with the function. */
257
257
  export declare const callFrom: (...args: AnyArgs) => any;
258
258
  export declare const complement: (fn: AnyFunc) => (...args: any) => boolean | any;
259
259
  export declare const sizeof: (s: any[] | string | AnyObject) => number;
@@ -271,6 +271,12 @@ export declare const intersection: {
271
271
  (a: any[]): (b: any[]) => any[];
272
272
  (a: any[], b: any[]): any[];
273
273
  };
274
+ export declare const diff: {
275
+ (a: symbol, b: any[]): (a: any[]) => any[];
276
+ (a: any[], b: symbol): (b: any[]) => any[];
277
+ (a: any[]): (b: any[]) => any[];
278
+ (a: any[], b: any[]): any[];
279
+ };
274
280
  export declare const genBy: {
275
281
  (a: symbol, b: number): (a: (i: number) => any) => any[];
276
282
  (a: (i: number) => any, b: symbol): (b: number) => any[];
@@ -495,6 +501,9 @@ export declare const some: {
495
501
  (a: Cond): (b: any[]) => boolean;
496
502
  (a: Cond, b: any[]): boolean;
497
503
  };
504
+ /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
505
+ * qflat, qpick
506
+ */
498
507
  export declare const qappend: {
499
508
  (a: symbol, b: any[]): (a: any) => any[];
500
509
  (a: any, b: symbol): (b: any[]) => any[];
@@ -581,17 +590,17 @@ export declare const forEachSerial: {
581
590
  (a: AnyFunc, b: any[]): Promise<void>;
582
591
  };
583
592
  /** Promise.all wrapper for functional pipelining. */
584
- export declare const waitAll: (promises: Promise<any>[]) => Promise<any[]>;
593
+ export declare const waitAll: <T>(promises: Promise<T>[]) => Promise<Awaited<T>[]>;
585
594
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
586
595
  * @param {AnyFunc<Promise>} fn - function to wait.
587
596
  * @param {T} s - any value to tap and return back
588
597
  * @returns {T}
589
598
  */
590
599
  export declare const waitTap: {
591
- (a: symbol, b: any): (a: AnyFunc) => Promise<any>;
592
- (a: AnyFunc, b: symbol): (b: any) => Promise<any>;
593
- (a: AnyFunc): (b: any) => Promise<any>;
594
- (a: AnyFunc, b: any): Promise<any>;
600
+ (a: symbol, b: any): (a: AnyFunc<Promise<any>>) => Promise<any>;
601
+ (a: AnyFunc<Promise<any>>, b: symbol): (b: any) => Promise<any>;
602
+ (a: AnyFunc<Promise<any>>): (b: any) => Promise<any>;
603
+ (a: AnyFunc<Promise<any>>, b: any): Promise<any>;
595
604
  };
596
605
  /** Waits for all promises mapped by the fn. */
597
606
  export declare const forEachAsync: {
package/dist/bundle.mjs CHANGED
@@ -134,7 +134,10 @@ const qstartsWithWith = (comparator) => curry2((start, s) => {
134
134
  return true;
135
135
  });
136
136
 
137
- // TODO: qflat, qoverProp, qover array ?
137
+ // TODO: qoverProp, qover array ?
138
+ /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
139
+ * qflat, qpick
140
+ */
138
141
  const qappend = curry2((s, xs) => { xs.push(s); return xs; });
139
142
  const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
140
143
  const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
@@ -276,15 +279,15 @@ const tail = slice(1, inf);
276
279
  const add = curry2((a, b) => a + b);
277
280
  /** @param a @param b @returns b-a */
278
281
  const subtract = curry2((a, b) => b - a);
279
- /**@param a @param b @returns a*b */
282
+ /**@param a @param b @returns a×b */
280
283
  const multiply = curry2((a, b) => a * b);
281
284
  /** @param a @param b @returns a<b */
282
285
  const gt = curry2((a, b) => a < b);
283
286
  /** @param a @param b @returns a>b */
284
287
  const lt = curry2((a, b) => a > b);
285
- /** @param a @param b @returns a<=b */
288
+ /** @param a @param b @returns ab */
286
289
  const gte = curry2((a, b) => a <= b);
287
- /** @param a @param b @returns a>=b */
290
+ /** @param a @param b @returns ab */
288
291
  const lte = curry2((a, b) => a >= b);
289
292
  const sort = curry2((sortFn, xs) => xs.sort(sortFn));
290
293
  const find = curry2((fn, s) => s.find(fn));
@@ -314,9 +317,9 @@ const F = always(false);
314
317
  const callWith = curry2((args, fn) => fn(...args));
315
318
  const noop = (() => { });
316
319
  /** Calls a func from object.
317
- * @param {any[]} [args] - arguments for the function.
318
- * @param {string} [fnName] - property name of the function.
319
- * @param {AnyObject} [o] - the object with the function. */
320
+ * @param {any[]} args - arguments for the function.
321
+ * @param {string} fnName - property name of the function.
322
+ * @param {AnyObject} o - the object with the function. */
320
323
  const callFrom = curry((args, fn, o) => o[fn](...args));
321
324
  const complement = (fn) => (...args) => {
322
325
  const out = fn(...args);
@@ -337,6 +340,29 @@ const range = curry2((from, to) => genBy(add(from), to - from));
337
340
  /** @param xs any[] @returns xs without duplicates. */
338
341
  const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
339
342
  const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
343
+ const diff = curry2((_xs1, _xs2) => {
344
+ const len1 = length(_xs1);
345
+ const len2 = length(_xs2); // xs2 should be shorter 4 Set mem consumption.
346
+ const xs1 = len1 > len2 ? _xs1 : _xs2;
347
+ const xs2 = len1 > len2 ? _xs2 : _xs1;
348
+ const xset2 = new Set(xs2);
349
+ const common = new Set();
350
+ const out = [];
351
+ let i;
352
+ for (i = 0; i < len1; i++) {
353
+ const el = xs1[i];
354
+ if (xset2.has(el))
355
+ common.add(el);
356
+ else
357
+ out.push(el);
358
+ }
359
+ for (i = 0; i < len2; i++) {
360
+ const el = xs2[i];
361
+ if (!common.has(el))
362
+ out.push(el);
363
+ }
364
+ return out;
365
+ });
340
366
  const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
341
367
  const once = (fn) => {
342
368
  let done = false, cache;
@@ -564,4 +590,4 @@ const composeAsync = (() => {
564
590
  return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
565
591
  })();
566
592
 
567
- 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, 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, qprepend, qreduce, qreverse, qstartsWith, qstartsWithWith, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, subtract, symbol, tail, take, tap, test, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, values, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
593
+ 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, 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, qprepend, qreduce, qreverse, qstartsWith, qstartsWithWith, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, subtract, symbol, tail, take, tap, test, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, values, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
package/package.json CHANGED
@@ -43,7 +43,7 @@
43
43
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
44
44
  "all": "npm run dev && npm run prod"
45
45
  },
46
- "version": "1.3.1",
46
+ "version": "1.4.2",
47
47
  "ava": {
48
48
  "files": [
49
49
  "./test/specs/*.ts"
package/src/async.ts CHANGED
@@ -15,17 +15,16 @@ export const forEachSerial = (() => {
15
15
  )
16
16
  })()
17
17
  /** Promise.all wrapper for functional pipelining. */
18
- export const waitAll = (promises: Promise<any>[]) => Promise.all(promises)
18
+ export const waitAll = <T>(promises: Promise<T>[]) => Promise.all<T>(promises)
19
19
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
20
20
  * @param {AnyFunc<Promise>} fn - function to wait.
21
21
  * @param {T} s - any value to tap and return back
22
22
  * @returns {T}
23
23
  */
24
- export const waitTap = curry2(async (fn: AnyFunc, s: any) => { await fn(s); return s })
24
+ export const waitTap = curry2(async (fn: AnyFunc<Promise<any>>, s: any) => { await fn(s); return s })
25
25
  /** Waits for all promises mapped by the fn. */
26
26
  export const forEachAsync = curry2(
27
- (fn: (item: any) => Promise<any>, items: any[]) =>
28
- Promise.all(items.map(fn))
27
+ (fn: (item: any) => Promise<any>, items: any[]) => Promise.all(items.map(fn))
29
28
  )
30
29
  /** The same as compose, but waits for promises in chains and returns a Promise. */
31
30
  export const composeAsync = (() => {
package/src/common.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { curry2 } from "./curry"
2
- import { BasicType } from "./types"
3
2
  import { to, isNull, isStr, isUndef } from "./utils"
4
3
 
5
4
  // It's faster that toUpperCase() !
package/src/quick.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { curry2, curry3 } from "./curry"
2
- import { includes, isNil, type, length, eq, qstartsWithWith } from "./common"
2
+ import { includes, isNil, type, eq, qstartsWithWith } from "./common"
3
3
  import { AnyObject, Reducer, AnyFunc } from "./types"
4
4
  import { isFunc, isArray, isObj } from "./utils"
5
- // TODO: qflat, qoverProp, qover array ?
5
+ // TODO: qoverProp, qover array ?
6
+
7
+ /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
8
+ * qflat, qpick
9
+ */
6
10
 
7
11
  export const qappend = curry2((s: any, xs: any[]) => {xs.push(s); return xs})
8
12
  export const qassoc = curry3((prop: string, v: any, obj: AnyObject) => { obj[prop] = v; return obj })
package/src/safe.ts CHANGED
@@ -57,15 +57,15 @@ export const tail = slice(1, inf)
57
57
  export const add = curry2((a: number, b: number) => a+b)
58
58
  /** @param a @param b @returns b-a */
59
59
  export const subtract = curry2((a: number, b: number) => b-a)
60
- /**@param a @param b @returns a*b */
60
+ /**@param a @param b @returns a×b */
61
61
  export const multiply = curry2((a: number, b: number) => a*b)
62
62
  /** @param a @param b @returns a<b */
63
63
  export const gt = curry2( (a: number, b: number) => a<b )
64
64
  /** @param a @param b @returns a>b */
65
65
  export const lt = curry2( (a: number, b: number) => a>b )
66
- /** @param a @param b @returns a<=b */
66
+ /** @param a @param b @returns ab */
67
67
  export const gte = curry2( (a: number, b: number) => a<=b )
68
- /** @param a @param b @returns a>=b */
68
+ /** @param a @param b @returns ab */
69
69
  export const lte = curry2( (a: number, b: number) => a>=b )
70
70
  export const sort = curry2((sortFn: any, xs: any[]) => xs.sort(sortFn))
71
71
  export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
@@ -107,9 +107,9 @@ export const F = always<false>(false) as (...args: any[]) => false
107
107
  export const callWith = curry2((args: any[], fn: AnyFunc) => fn(...args))
108
108
  export const noop = (()=>{}) as (...args: any[]) => any
109
109
  /** Calls a func from object.
110
- * @param {any[]} [args] - arguments for the function.
111
- * @param {string} [fnName] - property name of the function.
112
- * @param {AnyObject} [o] - the object with the function. */
110
+ * @param {any[]} args - arguments for the function.
111
+ * @param {string} fnName - property name of the function.
112
+ * @param {AnyObject} o - the object with the function. */
113
113
  export const callFrom = curry((args: any[], fn: string, o: AnyObject) => o[fn](...args))
114
114
  export const complement = (fn: AnyFunc) => (...args: any) => {
115
115
  const out = fn(...args)
@@ -129,9 +129,27 @@ export const uniq = (xs: any[]) => qreduce(
129
129
  <T>(accum: any, x: T) =>
130
130
  find(equals(x), accum) ? accum : qappend(x, accum),
131
131
  [], xs)
132
- export const intersection = curry2(
133
- (xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2))
134
- )
132
+ export const intersection = curry2((xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2)))
133
+ export const diff = curry2((_xs1: any[], _xs2: any[]) => {
134
+ const len1 = length(_xs1)
135
+ const len2 = length(_xs2) // xs2 should be shorter 4 Set mem consumption.
136
+ const xs1 = len1>len2 ? _xs1 : _xs2
137
+ const xs2 = len1>len2 ? _xs2 : _xs1
138
+ const xset2 = new Set(xs2)
139
+ const common = new Set()
140
+ const out: any[] = []
141
+ let i: number
142
+ for(i=0; i<len1; i++) {
143
+ const el = xs1[i]
144
+ if(xset2.has(el)) common.add(el)
145
+ else out.push(el)
146
+ }
147
+ for(i=0; i<len2; i++) {
148
+ const el = xs2[i]
149
+ if(!common.has(el)) out.push(el)
150
+ }
151
+ return out
152
+ })
135
153
  export const genBy = curry2(
136
154
  (
137
155
  generator: (i: number) => any,