pepka 1.6.0 → 1.6.1
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 +12 -7
- package/dist/bundle.d.ts +27 -17
- package/dist/bundle.mjs +12 -8
- package/package.json +1 -1
- package/src/common.ts +3 -2
- package/src/curry.ts +4 -4
- package/src/internal_types.ts +5 -1
- package/src/quick.ts +7 -6
- package/src/safe.ts +12 -10
package/dist/bundle.cjs
CHANGED
|
@@ -136,9 +136,9 @@ const qstartsWithWith = (comparator) => curry2((start, s) => {
|
|
|
136
136
|
return true;
|
|
137
137
|
});
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
140
|
+
* qflat, qpick
|
|
141
|
+
*/
|
|
142
142
|
const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
143
143
|
const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
|
|
144
144
|
const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
@@ -193,6 +193,7 @@ const qmapKeys = curry2((keyMap, o) => {
|
|
|
193
193
|
}
|
|
194
194
|
return o;
|
|
195
195
|
});
|
|
196
|
+
// FIXME: qmap(any, tags) -> some function!!!
|
|
196
197
|
const qmap = curry2((pipe, arr) => {
|
|
197
198
|
for (const i in arr)
|
|
198
199
|
arr[i] = pipe(arr[i], +i, arr);
|
|
@@ -246,15 +247,15 @@ const qreverse = (arr) => arr.reverse();
|
|
|
246
247
|
const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
|
|
247
248
|
/** @param start string | any[] @param s string | any[] */
|
|
248
249
|
const qstartsWith = qstartsWithWith(eq);
|
|
249
|
-
/** @param prop string @param pipe(data[prop]) @param data any
|
|
250
|
+
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
251
|
+
* @returns data with prop over pipe. */
|
|
250
252
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
251
253
|
|
|
252
254
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
253
255
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
254
256
|
|
|
255
|
-
// over, lensProp
|
|
257
|
+
// TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
|
|
256
258
|
const take = (argN) => (...args) => args[argN];
|
|
257
|
-
const weakEq = curry2((a, b) => a == b);
|
|
258
259
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
259
260
|
const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
|
|
260
261
|
const compose = ((...fns) => (...args) => {
|
|
@@ -343,8 +344,10 @@ const sizeof = (s) => {
|
|
|
343
344
|
return length(s);
|
|
344
345
|
};
|
|
345
346
|
const range = curry2((from, to) => genBy(add(from), to - from));
|
|
347
|
+
/** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
|
|
348
|
+
const uniqWith = curry2((cond, xs) => qreduce((accum, x) => find((y) => cond(x, y), accum) ? accum : qappend(x, accum), [], xs));
|
|
346
349
|
/** @param xs any[] @returns xs without duplicates. */
|
|
347
|
-
const uniq = (
|
|
350
|
+
const uniq = uniqWith(equals);
|
|
348
351
|
const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
|
|
349
352
|
const diff = curry2((_xs1, _xs2) => {
|
|
350
353
|
let len1 = length(_xs1);
|
|
@@ -532,6 +535,7 @@ const echo = identity;
|
|
|
532
535
|
const notf = complement;
|
|
533
536
|
const push = append;
|
|
534
537
|
const some = any;
|
|
538
|
+
const weakEq = eq;
|
|
535
539
|
|
|
536
540
|
const ecran = '\\';
|
|
537
541
|
// TODO: make it splicy, not accumulatie by symbols.
|
|
@@ -751,6 +755,7 @@ exports.type = type;
|
|
|
751
755
|
exports.typeIs = typeIs;
|
|
752
756
|
exports.uncurry = uncurry;
|
|
753
757
|
exports.uniq = uniq;
|
|
758
|
+
exports.uniqWith = uniqWith;
|
|
754
759
|
exports.values = values;
|
|
755
760
|
exports.waitAll = waitAll;
|
|
756
761
|
exports.waitTap = waitTap;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ type Split<S extends string> = S extends `${infer U}${infer V}` ? [
|
|
|
9
9
|
];
|
|
10
10
|
type IndexesOfArray<A> = Exclude<keyof A, keyof [
|
|
11
11
|
]>;
|
|
12
|
+
type StrLen<S extends string, Acc extends 0[] = [
|
|
13
|
+
]> = S extends `${string}${infer Rest}` ? StrLen<Rest, [
|
|
14
|
+
...Acc,
|
|
15
|
+
0
|
|
16
|
+
]> : Acc["length"];
|
|
12
17
|
export type Cond = (x1?: any, x2?: any, x3?: any) => boolean;
|
|
13
18
|
export interface AnyObject {
|
|
14
19
|
[k: string]: any;
|
|
@@ -39,7 +44,7 @@ export declare const typeIs: {
|
|
|
39
44
|
(a: string): (b: any) => boolean;
|
|
40
45
|
(a: string, b: any): boolean;
|
|
41
46
|
};
|
|
42
|
-
declare const length$1: (s:
|
|
47
|
+
declare const length$1: <T extends string | AnyArray>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
43
48
|
export declare const isNil: (s: any) => boolean;
|
|
44
49
|
export declare const eq: {
|
|
45
50
|
(a: symbol, b: any): (a: any) => boolean;
|
|
@@ -67,12 +72,6 @@ export declare const qstartsWithWith: (comparator: (x: any, y: any) => boolean)
|
|
|
67
72
|
(a: string | any[], b: string | any[]): boolean;
|
|
68
73
|
};
|
|
69
74
|
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
70
|
-
export declare const weakEq: {
|
|
71
|
-
(a: symbol, b: any): (a: any) => boolean;
|
|
72
|
-
(a: any, b: symbol): (b: any) => boolean;
|
|
73
|
-
(a: any): (b: any) => boolean;
|
|
74
|
-
(a: any, b: any): boolean;
|
|
75
|
-
};
|
|
76
75
|
export declare const ifElse: (...args: AnyArgs) => any;
|
|
77
76
|
export declare const when: (...args: AnyArgs) => any;
|
|
78
77
|
type Composed<TIn extends any[], TOut> = (...xs: TIn) => TOut;
|
|
@@ -211,8 +210,8 @@ export declare const divide: {
|
|
|
211
210
|
(a: number): (b: number) => number;
|
|
212
211
|
(a: number, b: number): number;
|
|
213
212
|
};
|
|
214
|
-
export declare const always: <T
|
|
215
|
-
export declare const identity: <T
|
|
213
|
+
export declare const always: <T extends unknown>(s: T) => () => T;
|
|
214
|
+
export declare const identity: <T extends unknown>(s: T) => T;
|
|
216
215
|
export declare const trim: (s: string) => string;
|
|
217
216
|
/** @param start string | any[] @param s string | any[] */
|
|
218
217
|
export declare const startsWith: {
|
|
@@ -298,8 +297,15 @@ export declare const range: {
|
|
|
298
297
|
(a: number): (b: number) => any[];
|
|
299
298
|
(a: number, b: number): any[];
|
|
300
299
|
};
|
|
300
|
+
/** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
|
|
301
|
+
export declare const uniqWith: {
|
|
302
|
+
(a: symbol, b: any[]): (a: (x: any, y: any) => boolean) => any;
|
|
303
|
+
(a: (x: any, y: any) => boolean, b: symbol): (b: any[]) => any;
|
|
304
|
+
(a: (x: any, y: any) => boolean): (b: any[]) => any;
|
|
305
|
+
(a: (x: any, y: any) => boolean, b: any[]): any;
|
|
306
|
+
};
|
|
301
307
|
/** @param xs any[] @returns xs without duplicates. */
|
|
302
|
-
export declare const uniq: (
|
|
308
|
+
export declare const uniq: (b: any[]) => any;
|
|
303
309
|
export declare const intersection: {
|
|
304
310
|
(a: symbol, b: any[]): (a: any[]) => any[];
|
|
305
311
|
(a: any[], b: symbol): (b: any[]) => any[];
|
|
@@ -530,9 +536,9 @@ export declare const zipObj: {
|
|
|
530
536
|
* @param b T2[]
|
|
531
537
|
*/
|
|
532
538
|
export declare const zipWith: (...args: AnyArgs) => any;
|
|
533
|
-
export declare const mirror: <T
|
|
534
|
-
export declare const reflect: <T
|
|
535
|
-
export declare const echo: <T
|
|
539
|
+
export declare const mirror: <T extends unknown>(s: T) => T;
|
|
540
|
+
export declare const reflect: <T extends unknown>(s: T) => T;
|
|
541
|
+
export declare const echo: <T extends unknown>(s: T) => T;
|
|
536
542
|
export declare const notf: (fn: AnyFunc) => (...args: any) => boolean | any;
|
|
537
543
|
export declare const push: {
|
|
538
544
|
(a: symbol, b: any[]): (a: any) => any[];
|
|
@@ -546,9 +552,12 @@ export declare const some: {
|
|
|
546
552
|
(a: Cond): (b: any[]) => boolean;
|
|
547
553
|
(a: Cond, b: any[]): boolean;
|
|
548
554
|
};
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
555
|
+
export declare const weakEq: {
|
|
556
|
+
(a: symbol, b: any): (a: any) => boolean;
|
|
557
|
+
(a: any, b: symbol): (b: any) => boolean;
|
|
558
|
+
(a: any): (b: any) => boolean;
|
|
559
|
+
(a: any, b: any): boolean;
|
|
560
|
+
};
|
|
552
561
|
export declare const qappend: {
|
|
553
562
|
(a: symbol, b: any[]): (a: any) => any[];
|
|
554
563
|
(a: any, b: symbol): (b: any[]) => any[];
|
|
@@ -639,7 +648,8 @@ export declare const qstartsWith: {
|
|
|
639
648
|
(a: string | any[]): (b: string | any[]) => boolean;
|
|
640
649
|
(a: string | any[], b: string | any[]): boolean;
|
|
641
650
|
};
|
|
642
|
-
/** @param prop string @param pipe(data[prop]) @param data any
|
|
651
|
+
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
652
|
+
* @returns data with prop over pipe. */
|
|
643
653
|
export declare const qoverProp: (...args: AnyArgs) => any;
|
|
644
654
|
type StrTmpl = ((data: AnyObject) => string);
|
|
645
655
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
package/dist/bundle.mjs
CHANGED
|
@@ -134,9 +134,9 @@ const qstartsWithWith = (comparator) => curry2((start, s) => {
|
|
|
134
134
|
return true;
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
138
|
+
* qflat, qpick
|
|
139
|
+
*/
|
|
140
140
|
const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
141
141
|
const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
|
|
142
142
|
const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
@@ -191,6 +191,7 @@ const qmapKeys = curry2((keyMap, o) => {
|
|
|
191
191
|
}
|
|
192
192
|
return o;
|
|
193
193
|
});
|
|
194
|
+
// FIXME: qmap(any, tags) -> some function!!!
|
|
194
195
|
const qmap = curry2((pipe, arr) => {
|
|
195
196
|
for (const i in arr)
|
|
196
197
|
arr[i] = pipe(arr[i], +i, arr);
|
|
@@ -244,15 +245,15 @@ const qreverse = (arr) => arr.reverse();
|
|
|
244
245
|
const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
|
|
245
246
|
/** @param start string | any[] @param s string | any[] */
|
|
246
247
|
const qstartsWith = qstartsWithWith(eq);
|
|
247
|
-
/** @param prop string @param pipe(data[prop]) @param data any
|
|
248
|
+
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
249
|
+
* @returns data with prop over pipe. */
|
|
248
250
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
249
251
|
|
|
250
252
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
251
253
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
252
254
|
|
|
253
|
-
// over, lensProp
|
|
255
|
+
// TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
|
|
254
256
|
const take = (argN) => (...args) => args[argN];
|
|
255
|
-
const weakEq = curry2((a, b) => a == b);
|
|
256
257
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
257
258
|
const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
|
|
258
259
|
const compose = ((...fns) => (...args) => {
|
|
@@ -341,8 +342,10 @@ const sizeof = (s) => {
|
|
|
341
342
|
return length(s);
|
|
342
343
|
};
|
|
343
344
|
const range = curry2((from, to) => genBy(add(from), to - from));
|
|
345
|
+
/** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
|
|
346
|
+
const uniqWith = curry2((cond, xs) => qreduce((accum, x) => find((y) => cond(x, y), accum) ? accum : qappend(x, accum), [], xs));
|
|
344
347
|
/** @param xs any[] @returns xs without duplicates. */
|
|
345
|
-
const uniq = (
|
|
348
|
+
const uniq = uniqWith(equals);
|
|
346
349
|
const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
|
|
347
350
|
const diff = curry2((_xs1, _xs2) => {
|
|
348
351
|
let len1 = length(_xs1);
|
|
@@ -530,6 +533,7 @@ const echo = identity;
|
|
|
530
533
|
const notf = complement;
|
|
531
534
|
const push = append;
|
|
532
535
|
const some = any;
|
|
536
|
+
const weakEq = eq;
|
|
533
537
|
|
|
534
538
|
const ecran = '\\';
|
|
535
539
|
// TODO: make it splicy, not accumulatie by symbols.
|
|
@@ -610,4 +614,4 @@ const composeAsync = (() => {
|
|
|
610
614
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
611
615
|
})();
|
|
612
616
|
|
|
613
|
-
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, qoverProp, 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 };
|
|
617
|
+
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, qoverProp, 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, uniqWith, values, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
package/package.json
CHANGED
package/src/common.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
|
-
import { AnyArray } from "./internal_types"
|
|
2
|
+
import { AnyArray, StrLen } from "./internal_types"
|
|
3
3
|
import { to, isNull, isStr, isUndef } from "./utils"
|
|
4
4
|
|
|
5
5
|
// It's faster that toUpperCase() !
|
|
@@ -15,7 +15,8 @@ export const type = (s: any): string => {
|
|
|
15
15
|
: caseMap[t[0]] + t.slice(1)
|
|
16
16
|
}
|
|
17
17
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
18
|
-
|
|
18
|
+
|
|
19
|
+
export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T["length"] => s.length as any
|
|
19
20
|
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
20
21
|
export const eq = curry2((a: any, b: any) => a===b)
|
|
21
22
|
export const equals = curry2((a: any, b: any) => {
|
package/src/curry.ts
CHANGED
|
@@ -75,10 +75,10 @@ export function curry2<Func extends Func2>(fn: Func) {
|
|
|
75
75
|
if(aln === 1 && withPlaceholder1)
|
|
76
76
|
throw new Error('Senseless placeholder usage.')
|
|
77
77
|
return aln>1
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
? withPlaceholder1
|
|
79
|
+
? endlessph((a: p0) => fn(a, b))
|
|
80
|
+
: fn(a, b) as ReturnType<Func>
|
|
81
|
+
: (b: p1) => fn(a, b)
|
|
82
82
|
}
|
|
83
83
|
return curried2
|
|
84
84
|
}
|
package/src/internal_types.ts
CHANGED
|
@@ -4,4 +4,8 @@ export type TupleFn<ARG1=any, ARG2=any, Out=any> = (a: ARG1, b: ARG2) => Out
|
|
|
4
4
|
export type IDArray = Uint8Array|Uint16Array|Uint32Array
|
|
5
5
|
export type AnyArray<T=any> = T[] | readonly T[]
|
|
6
6
|
export type Split<S extends string> = S extends `${infer U}${infer V}` ? [U, ...Split<V>] : []
|
|
7
|
-
export type IndexesOfArray<A> = Exclude<keyof A, keyof []>
|
|
7
|
+
export type IndexesOfArray<A> = Exclude<keyof A, keyof []>
|
|
8
|
+
export type StrLen<S extends string, Acc extends 0[] = []> =
|
|
9
|
+
S extends `${string}${infer Rest}`
|
|
10
|
+
? StrLen<Rest, [...Acc, 0]>
|
|
11
|
+
: Acc["length"]
|
package/src/quick.ts
CHANGED
|
@@ -2,9 +2,9 @@ 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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
6
|
+
* qflat, qpick
|
|
7
|
+
*/
|
|
8
8
|
|
|
9
9
|
export const qappend = curry2((s: any, xs: any[]) => {xs.push(s); return xs})
|
|
10
10
|
export const qassoc = curry3((prop: string, v: any, obj: AnyObject) => { obj[prop] = v; return obj })
|
|
@@ -61,6 +61,7 @@ export const qmapKeys = curry2(
|
|
|
61
61
|
return o
|
|
62
62
|
}
|
|
63
63
|
)
|
|
64
|
+
// FIXME: qmap(any, tags) -> some function!!!
|
|
64
65
|
export const qmap = curry2(
|
|
65
66
|
(pipe: (s: any, i?: number, list?: any[]) => any, arr: any[]) => {
|
|
66
67
|
for(const i in arr) arr[i] = pipe(arr[i], +i, arr)
|
|
@@ -123,8 +124,8 @@ export const qomit = curry2(
|
|
|
123
124
|
)
|
|
124
125
|
/** @param start string | any[] @param s string | any[] */
|
|
125
126
|
export const qstartsWith = qstartsWithWith(eq)
|
|
126
|
-
/** @param prop string @param pipe(data[prop]) @param data any
|
|
127
|
+
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
128
|
+
* @returns data with prop over pipe. */
|
|
127
129
|
export const qoverProp = curry3(
|
|
128
|
-
(prop: string, pipe: AnyFunc, data: any) =>
|
|
129
|
-
qassoc(prop, pipe(data[prop]), data)
|
|
130
|
+
(prop: string, pipe: AnyFunc, data: any) => qassoc(prop, pipe(data[prop]), data)
|
|
130
131
|
)
|
package/src/safe.ts
CHANGED
|
@@ -2,12 +2,11 @@ import { __, curry, curry2, curry3 } from './curry'
|
|
|
2
2
|
import { isNum, undef, isArray, isFunc, isObj, inf } from './utils'
|
|
3
3
|
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj } from './quick'
|
|
4
4
|
import { AnyFunc, Cond, AnyObject, Reducer } from './types'
|
|
5
|
-
import { symbol, type, length, equals, includes, isNil, qstartsWithWith } from './common'
|
|
5
|
+
import { symbol, type, length, equals, includes, isNil, qstartsWithWith, eq } from './common'
|
|
6
6
|
import { Split, AnyArray, IndexesOfArray } from './internal_types'
|
|
7
|
-
// over, lensProp
|
|
7
|
+
// TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
|
|
8
8
|
|
|
9
9
|
export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
10
|
-
export const weakEq = curry2((a: any, b: any) => a==b)
|
|
11
10
|
export const ifElse = curry(
|
|
12
11
|
(
|
|
13
12
|
cond: (s: any) => boolean,
|
|
@@ -103,8 +102,8 @@ export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
|
|
|
103
102
|
export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
|
|
104
103
|
export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
|
|
105
104
|
export const divide = curry2((a: number, b: number) => b/a)
|
|
106
|
-
export const always = <T
|
|
107
|
-
export const identity = <T
|
|
105
|
+
export const always = <T extends any>(s: T) => () => s
|
|
106
|
+
export const identity = <T extends any>(s: T) => s
|
|
108
107
|
export const trim = (s: string) => s.trim()
|
|
109
108
|
|
|
110
109
|
/** @param start string | any[] @param s string | any[] */
|
|
@@ -153,11 +152,13 @@ export const sizeof = (s: any[] | string | AnyObject) => {
|
|
|
153
152
|
} else return length(s as any[])
|
|
154
153
|
}
|
|
155
154
|
export const range = curry2((from: number, to: number) => genBy(add(from), to-from))
|
|
156
|
-
/** @param xs any[] @returns xs without duplicates. */
|
|
157
|
-
export const
|
|
155
|
+
/** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
|
|
156
|
+
export const uniqWith = curry2((cond: (x: any, y: any) => boolean, xs: any[]) => qreduce(
|
|
158
157
|
<T>(accum: any, x: T) =>
|
|
159
|
-
find(
|
|
160
|
-
[], xs)
|
|
158
|
+
find((y) => cond(x as any, y), accum) ? accum : qappend(x, accum),
|
|
159
|
+
[], xs))
|
|
160
|
+
/** @param xs any[] @returns xs without duplicates. */
|
|
161
|
+
export const uniq = uniqWith(equals)
|
|
161
162
|
export const intersection = curry2((xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2)))
|
|
162
163
|
export const diff = curry2((_xs1: any[], _xs2: any[]) => {
|
|
163
164
|
let len1 = length(_xs1)
|
|
@@ -425,4 +426,5 @@ export const reflect = identity
|
|
|
425
426
|
export const echo = identity
|
|
426
427
|
export const notf = complement
|
|
427
428
|
export const push = append
|
|
428
|
-
export const some = any
|
|
429
|
+
export const some = any
|
|
430
|
+
export const weakEq = eq
|