pepka 1.6.0 → 1.6.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,9 +136,9 @@ const qstartsWithWith = (comparator) => curry2((start, s) => {
136
136
  return true;
137
137
  });
138
138
 
139
- /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
140
- * qflat, qpick
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,12 +193,17 @@ 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);
199
200
  return arr;
200
201
  });
201
- const qmapObj = curry2((pipe, o) => qmap(pipe, o));
202
+ const qmapObj = curry2((pipe, o) => {
203
+ for (const k in o)
204
+ o[k] = pipe(o[k], k, o);
205
+ return o;
206
+ });
202
207
  const qfilter = curry2((cond, data) => {
203
208
  const isArr = isArray(data);
204
209
  let indicies_offset, indicies2rm;
@@ -246,15 +251,15 @@ const qreverse = (arr) => arr.reverse();
246
251
  const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
247
252
  /** @param start string | any[] @param s string | any[] */
248
253
  const qstartsWith = qstartsWithWith(eq);
249
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
254
+ /** @param prop string @param pipe (data[prop]): prop_value @param data any
255
+ * @returns data with prop over pipe. */
250
256
  const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
251
257
 
252
258
  // TODO: possibly introduce a second argument limiting unfolding.
253
259
  const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
254
260
 
255
- // over, lensProp
261
+ // TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
256
262
  const take = (argN) => (...args) => args[argN];
257
- const weakEq = curry2((a, b) => a == b);
258
263
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
259
264
  const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
260
265
  const compose = ((...fns) => (...args) => {
@@ -343,8 +348,10 @@ const sizeof = (s) => {
343
348
  return length(s);
344
349
  };
345
350
  const range = curry2((from, to) => genBy(add(from), to - from));
351
+ /** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
352
+ const uniqWith = curry2((cond, xs) => qreduce((accum, x) => find((y) => cond(x, y), accum) ? accum : qappend(x, accum), [], xs));
346
353
  /** @param xs any[] @returns xs without duplicates. */
347
- const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
354
+ const uniq = uniqWith(equals);
348
355
  const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
349
356
  const diff = curry2((_xs1, _xs2) => {
350
357
  let len1 = length(_xs1);
@@ -532,6 +539,7 @@ const echo = identity;
532
539
  const notf = complement;
533
540
  const push = append;
534
541
  const some = any;
542
+ const weakEq = eq;
535
543
 
536
544
  const ecran = '\\';
537
545
  // TODO: make it splicy, not accumulatie by symbols.
@@ -751,6 +759,7 @@ exports.type = type;
751
759
  exports.typeIs = typeIs;
752
760
  exports.uncurry = uncurry;
753
761
  exports.uniq = uniq;
762
+ exports.uniqWith = uniqWith;
754
763
  exports.values = values;
755
764
  exports.waitAll = waitAll;
756
765
  exports.waitTap = waitTap;
package/dist/bundle.d.ts CHANGED
@@ -9,9 +9,13 @@ 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
- export interface AnyObject {
14
- [k: string]: any;
18
+ export interface AnyObject extends Record<any, any> {
15
19
  }
16
20
  export type Reducer<T = any> = (accum: T, cur: any, index: number) => T;
17
21
  export type AnyFunc<ReturnT = any, Args extends AnyArgs = AnyArgs> = (...args: Args) => ReturnT;
@@ -39,7 +43,7 @@ export declare const typeIs: {
39
43
  (a: string): (b: any) => boolean;
40
44
  (a: string, b: any): boolean;
41
45
  };
42
- declare const length$1: (s: AnyArray | string) => number;
46
+ declare const length$1: <T extends string | AnyArray>(s: T) => T extends string ? StrLen<T> : T["length"];
43
47
  export declare const isNil: (s: any) => boolean;
44
48
  export declare const eq: {
45
49
  (a: symbol, b: any): (a: any) => boolean;
@@ -67,12 +71,6 @@ export declare const qstartsWithWith: (comparator: (x: any, y: any) => boolean)
67
71
  (a: string | any[], b: string | any[]): boolean;
68
72
  };
69
73
  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
74
  export declare const ifElse: (...args: AnyArgs) => any;
77
75
  export declare const when: (...args: AnyArgs) => any;
78
76
  type Composed<TIn extends any[], TOut> = (...xs: TIn) => TOut;
@@ -211,8 +209,8 @@ export declare const divide: {
211
209
  (a: number): (b: number) => number;
212
210
  (a: number, b: number): number;
213
211
  };
214
- export declare const always: <T = any>(s: T) => () => T;
215
- export declare const identity: <T = any>(s: T) => T;
212
+ export declare const always: <T extends unknown>(s: T) => () => T;
213
+ export declare const identity: <T extends unknown>(s: T) => T;
216
214
  export declare const trim: (s: string) => string;
217
215
  /** @param start string | any[] @param s string | any[] */
218
216
  export declare const startsWith: {
@@ -298,8 +296,15 @@ export declare const range: {
298
296
  (a: number): (b: number) => any[];
299
297
  (a: number, b: number): any[];
300
298
  };
299
+ /** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
300
+ export declare const uniqWith: {
301
+ (a: symbol, b: any[]): (a: (x: any, y: any) => boolean) => any;
302
+ (a: (x: any, y: any) => boolean, b: symbol): (b: any[]) => any;
303
+ (a: (x: any, y: any) => boolean): (b: any[]) => any;
304
+ (a: (x: any, y: any) => boolean, b: any[]): any;
305
+ };
301
306
  /** @param xs any[] @returns xs without duplicates. */
302
- export declare const uniq: (xs: any[]) => any;
307
+ export declare const uniq: (b: any[]) => any;
303
308
  export declare const intersection: {
304
309
  (a: symbol, b: any[]): (a: any[]) => any[];
305
310
  (a: any[], b: symbol): (b: any[]) => any[];
@@ -433,10 +438,10 @@ export declare const map: {
433
438
  (a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
434
439
  };
435
440
  export declare const mapObj: {
436
- (a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) => (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
437
- (a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
438
- (a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
439
- (a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): (b: AnyObject) => (a: (s: any, i?: number | undefined, list?: any[] | undefined) => any) => any[];
441
+ (a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) => (b: AnyObject) => AnyObject;
442
+ (a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => (b: AnyObject) => AnyObject;
443
+ (a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => (b: AnyObject) => AnyObject;
444
+ (a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): (b: AnyObject) => AnyObject;
440
445
  };
441
446
  export declare const join: {
442
447
  (a: symbol, b: string[]): (a: string) => string;
@@ -530,9 +535,9 @@ export declare const zipObj: {
530
535
  * @param b T2[]
531
536
  */
532
537
  export declare const zipWith: (...args: AnyArgs) => any;
533
- export declare const mirror: <T = any>(s: T) => T;
534
- export declare const reflect: <T = any>(s: T) => T;
535
- export declare const echo: <T = any>(s: T) => T;
538
+ export declare const mirror: <T extends unknown>(s: T) => T;
539
+ export declare const reflect: <T extends unknown>(s: T) => T;
540
+ export declare const echo: <T extends unknown>(s: T) => T;
536
541
  export declare const notf: (fn: AnyFunc) => (...args: any) => boolean | any;
537
542
  export declare const push: {
538
543
  (a: symbol, b: any[]): (a: any) => any[];
@@ -546,9 +551,12 @@ export declare const some: {
546
551
  (a: Cond): (b: any[]) => boolean;
547
552
  (a: Cond, b: any[]): boolean;
548
553
  };
549
- /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
550
- * qflat, qpick
551
- */
554
+ export declare const weakEq: {
555
+ (a: symbol, b: any): (a: any) => boolean;
556
+ (a: any, b: symbol): (b: any) => boolean;
557
+ (a: any): (b: any) => boolean;
558
+ (a: any, b: any): boolean;
559
+ };
552
560
  export declare const qappend: {
553
561
  (a: symbol, b: any[]): (a: any) => any[];
554
562
  (a: any, b: symbol): (b: any[]) => any[];
@@ -603,10 +611,10 @@ export declare const qmap: {
603
611
  (a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
604
612
  };
605
613
  export declare const qmapObj: {
606
- (a: symbol, b: AnyObject): (a: (s: any, k?: string, list?: any[]) => any) => (a: (s: any, i?: number, list?: any[]) => any) => any[];
607
- (a: (s: any, k?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => (a: (s: any, i?: number, list?: any[]) => any) => any[];
608
- (a: (s: any, k?: string, list?: any[]) => any): (b: AnyObject) => (a: (s: any, i?: number, list?: any[]) => any) => any[];
609
- (a: (s: any, k?: string, list?: any[]) => any, b: AnyObject): (a: (s: any, i?: number, list?: any[]) => any) => any[];
614
+ (a: symbol, b: AnyObject): (a: (s: any, k?: string, o?: AnyObject) => any) => AnyObject;
615
+ (a: (s: any, k?: string, o?: AnyObject) => any, b: symbol): (b: AnyObject) => AnyObject;
616
+ (a: (s: any, k?: string, o?: AnyObject) => any): (b: AnyObject) => AnyObject;
617
+ (a: (s: any, k?: string, o?: AnyObject) => any, b: AnyObject): AnyObject;
610
618
  };
611
619
  export declare const qfilter: {
612
620
  (a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any[] | AnyObject;
@@ -639,7 +647,8 @@ export declare const qstartsWith: {
639
647
  (a: string | any[]): (b: string | any[]) => boolean;
640
648
  (a: string | any[], b: string | any[]): boolean;
641
649
  };
642
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
650
+ /** @param prop string @param pipe (data[prop]): prop_value @param data any
651
+ * @returns data with prop over pipe. */
643
652
  export declare const qoverProp: (...args: AnyArgs) => any;
644
653
  type StrTmpl = ((data: AnyObject) => string);
645
654
  /** 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
- /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
138
- * qflat, qpick
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,12 +191,17 @@ 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);
197
198
  return arr;
198
199
  });
199
- const qmapObj = curry2((pipe, o) => qmap(pipe, o));
200
+ const qmapObj = curry2((pipe, o) => {
201
+ for (const k in o)
202
+ o[k] = pipe(o[k], k, o);
203
+ return o;
204
+ });
200
205
  const qfilter = curry2((cond, data) => {
201
206
  const isArr = isArray(data);
202
207
  let indicies_offset, indicies2rm;
@@ -244,15 +249,15 @@ const qreverse = (arr) => arr.reverse();
244
249
  const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
245
250
  /** @param start string | any[] @param s string | any[] */
246
251
  const qstartsWith = qstartsWithWith(eq);
247
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
252
+ /** @param prop string @param pipe (data[prop]): prop_value @param data any
253
+ * @returns data with prop over pipe. */
248
254
  const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
249
255
 
250
256
  // TODO: possibly introduce a second argument limiting unfolding.
251
257
  const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
252
258
 
253
- // over, lensProp
259
+ // TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
254
260
  const take = (argN) => (...args) => args[argN];
255
- const weakEq = curry2((a, b) => a == b);
256
261
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
257
262
  const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
258
263
  const compose = ((...fns) => (...args) => {
@@ -341,8 +346,10 @@ const sizeof = (s) => {
341
346
  return length(s);
342
347
  };
343
348
  const range = curry2((from, to) => genBy(add(from), to - from));
349
+ /** @param cond (x, y): bool @param xs any[] @returns xs without duplicates, using cond as a comparator. */
350
+ const uniqWith = curry2((cond, xs) => qreduce((accum, x) => find((y) => cond(x, y), accum) ? accum : qappend(x, accum), [], xs));
344
351
  /** @param xs any[] @returns xs without duplicates. */
345
- const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
352
+ const uniq = uniqWith(equals);
346
353
  const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
347
354
  const diff = curry2((_xs1, _xs2) => {
348
355
  let len1 = length(_xs1);
@@ -530,6 +537,7 @@ const echo = identity;
530
537
  const notf = complement;
531
538
  const push = append;
532
539
  const some = any;
540
+ const weakEq = eq;
533
541
 
534
542
  const ecran = '\\';
535
543
  // TODO: make it splicy, not accumulatie by symbols.
@@ -610,4 +618,4 @@ const composeAsync = (() => {
610
618
  return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
611
619
  })();
612
620
 
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 };
621
+ 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
@@ -42,7 +42,7 @@
42
42
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
43
43
  "all": "npm run dev && npm run prod"
44
44
  },
45
- "version": "1.6.0",
45
+ "version": "1.6.2",
46
46
  "ava": {
47
47
  "files": [
48
48
  "./test/specs/*.ts"
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
- export const length = (s: AnyArray | string) => s.length
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
- ? withPlaceholder1
79
- ? endlessph((a: p0) => fn(a, b))
80
- : fn(a, b) as ReturnType<Func>
81
- : (b: p1) => fn(a, b)
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
  }
@@ -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
- /** Then next fns seem to be excess due to their safe ver performance should be the same or better:
6
- * qflat, qpick
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)
@@ -68,7 +69,10 @@ export const qmap = curry2(
68
69
  }
69
70
  )
70
71
  export const qmapObj = curry2(
71
- (pipe: (s: any, k?: string, list?: any[]) => any, o: AnyObject) => qmap(pipe as any, o as any[])
72
+ (pipe: (s: any, k?: string, o?: AnyObject) => any, o: AnyObject) => {
73
+ for(const k in o) o[k] = pipe(o[k], k, o)
74
+ return o
75
+ }
72
76
  )
73
77
  export const qfilter = curry2(
74
78
  <T extends any[] | AnyObject>(
@@ -123,8 +127,8 @@ export const qomit = curry2(
123
127
  )
124
128
  /** @param start string | any[] @param s string | any[] */
125
129
  export const qstartsWith = qstartsWithWith(eq)
126
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
130
+ /** @param prop string @param pipe (data[prop]): prop_value @param data any
131
+ * @returns data with prop over pipe. */
127
132
  export const qoverProp = curry3(
128
- (prop: string, pipe: AnyFunc, data: any) =>
129
- qassoc(prop, pipe(data[prop]), data)
133
+ (prop: string, pipe: AnyFunc, data: any) => qassoc(prop, pipe(data[prop]), data)
130
134
  )
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=any>(s: T) => () => s
107
- export const identity = <T=any>(s: T) => s
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 uniq = (xs: any[]) => qreduce(
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(equals(x), accum) ? accum : qappend(x, accum),
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
package/src/types.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { AnyArgs } from "./internal_types"
2
2
 
3
3
  export type Cond = (x1?: any, x2?: any, x3?: any) => boolean
4
- export interface AnyObject { [k: string]: any }
4
+ export interface AnyObject extends Record<any, any> {}
5
5
  export type Reducer<T=any> = (accum: T, cur: any, index: number) => T
6
6
  export type AnyFunc<ReturnT = any, Args extends AnyArgs = AnyArgs> = (...args: Args) => ReturnT
7
7
  export type Curried<Args extends AnyArgs = AnyArgs, ReturnT = any> = (arg: Args[number]) => Curried<Args> | ReturnT