pepka 1.4.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 +33 -8
- package/dist/bundle.d.ts +14 -11
- package/dist/bundle.mjs +33 -8
- package/package.json +1 -1
- package/src/async.ts +3 -4
- package/src/common.ts +0 -1
- package/src/quick.ts +5 -1
- package/src/safe.ts +26 -7
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:
|
|
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
|
|
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
|
|
290
|
+
/** @param a @param b @returns a≤b */
|
|
288
291
|
const gte = curry2((a, b) => a <= b);
|
|
289
|
-
/** @param a @param b @returns a
|
|
292
|
+
/** @param a @param b @returns a≥b */
|
|
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[]}
|
|
320
|
-
* @param {string}
|
|
321
|
-
* @param {AnyObject}
|
|
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,7 +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)));
|
|
342
|
-
const diff = curry2((
|
|
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
|
+
});
|
|
343
368
|
const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
|
|
344
369
|
const once = (fn) => {
|
|
345
370
|
let done = false, cache;
|
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
|
|
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
|
|
132
|
+
/** @param a @param b @returns a≤b */
|
|
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
|
|
139
|
+
/** @param a @param b @returns a≥b */
|
|
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[]}
|
|
255
|
-
* @param {string}
|
|
256
|
-
* @param {AnyObject}
|
|
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;
|
|
@@ -501,6 +501,9 @@ export declare const some: {
|
|
|
501
501
|
(a: Cond): (b: any[]) => boolean;
|
|
502
502
|
(a: Cond, b: any[]): boolean;
|
|
503
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
|
+
*/
|
|
504
507
|
export declare const qappend: {
|
|
505
508
|
(a: symbol, b: any[]): (a: any) => any[];
|
|
506
509
|
(a: any, b: symbol): (b: any[]) => any[];
|
|
@@ -587,17 +590,17 @@ export declare const forEachSerial: {
|
|
|
587
590
|
(a: AnyFunc, b: any[]): Promise<void>;
|
|
588
591
|
};
|
|
589
592
|
/** Promise.all wrapper for functional pipelining. */
|
|
590
|
-
export declare const waitAll: (promises: Promise<
|
|
593
|
+
export declare const waitAll: <T>(promises: Promise<T>[]) => Promise<Awaited<T>[]>;
|
|
591
594
|
/** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
|
|
592
595
|
* @param {AnyFunc<Promise>} fn - function to wait.
|
|
593
596
|
* @param {T} s - any value to tap and return back
|
|
594
597
|
* @returns {T}
|
|
595
598
|
*/
|
|
596
599
|
export declare const waitTap: {
|
|
597
|
-
(a: symbol, b: any): (a: AnyFunc) => Promise<any>;
|
|
598
|
-
(a: AnyFunc
|
|
599
|
-
(a: AnyFunc): (b: any) => Promise<any>;
|
|
600
|
-
(a: AnyFunc
|
|
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>;
|
|
601
604
|
};
|
|
602
605
|
/** Waits for all promises mapped by the fn. */
|
|
603
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:
|
|
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
|
|
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
|
|
288
|
+
/** @param a @param b @returns a≤b */
|
|
286
289
|
const gte = curry2((a, b) => a <= b);
|
|
287
|
-
/** @param a @param b @returns a
|
|
290
|
+
/** @param a @param b @returns a≥b */
|
|
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[]}
|
|
318
|
-
* @param {string}
|
|
319
|
-
* @param {AnyObject}
|
|
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,7 +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)));
|
|
340
|
-
const diff = curry2((
|
|
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
|
+
});
|
|
341
366
|
const genBy = curry2((generator, length) => [...Array(length)].map((_, i) => generator(i)));
|
|
342
367
|
const once = (fn) => {
|
|
343
368
|
let done = false, cache;
|
package/package.json
CHANGED
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<
|
|
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
|
|
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
package/src/quick.ts
CHANGED
|
@@ -2,7 +2,11 @@ import { curry2, curry3 } from "./curry"
|
|
|
2
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:
|
|
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
|
|
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
|
|
66
|
+
/** @param a @param b @returns a≤b */
|
|
67
67
|
export const gte = curry2( (a: number, b: number) => a<=b )
|
|
68
|
-
/** @param a @param b @returns a
|
|
68
|
+
/** @param a @param b @returns a≥b */
|
|
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[]}
|
|
111
|
-
* @param {string}
|
|
112
|
-
* @param {AnyObject}
|
|
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)
|
|
@@ -130,7 +130,26 @@ export const uniq = (xs: any[]) => qreduce(
|
|
|
130
130
|
find(equals(x), accum) ? accum : qappend(x, accum),
|
|
131
131
|
[], xs)
|
|
132
132
|
export const intersection = curry2((xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2)))
|
|
133
|
-
export const diff = curry2(
|
|
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
|
+
})
|
|
134
153
|
export const genBy = curry2(
|
|
135
154
|
(
|
|
136
155
|
generator: (i: number) => any,
|