// TypeScript Version: 3.4 import { Iter, EP, Find, PairRepeat, PickElements, Accumulator, FlatAccumulator, FlatForInternalFn, ReturnTypePickElements, ExtractPromise, } from "./utils"; import { Getter } from "./core"; /** * https://github.com/rudty/nodekell#otherwise */ export function otherwise(): true; /** * https://github.com/rudty/nodekell#cond * * Requires an even number of arguments * * if the first argument is true, it returns the second argument */ export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; export function cond | typeof otherwise, any>>(...a: T): Promise | typeof otherwise, T> extends never ? PickElements<1, T> | undefined : PickElements<1, T>>>; /** * * * **Note** * - if use overloaded type function, use generic * ```ts * const addn = F.memoizeBy<(a: number, b: number) => number>((...e) => e, F.add); * addn(1, 2); * const adds = F.memoizeBy<(a: string, b: string) => string>((...e) => e, F.add); * adds('a', 'b'); * const add = F.memoizeBy<((a: string, b: string) => string) | ((a: number, b: number) => number)>((...e) => e, F.add); * add('a', 'b') as string; * add(1, 2) as number; * ``` * @param keyFn * @param callFn */ export function memoizeBy

(keyFn: (...args: P) => any, callFn: (...args: P) => (R | Promise)): (...args: P) => Promise; export function memoizeBy any>(keyFn: (...args: Parameters) => any, callFn: F): (...args: Parameters) => Promise>>; export function memoizeBy

(keyFn: (...args: P) => any): (callFn: (...args: P) => (R | Promise)) => (...args: P) => Promise; export function memoizeBy any>(keyFn: (...args: Parameters) => any): (callFn: F) => (...args: Parameters) => Promise>>; /** * * * **Note** * - if use overloaded type function, use generic * ```ts * const addn = F.memoize<(a: number, b: number) => number>(F.add); * addn(1, 2); * const adds = F.memoize<(a: string, b: string) => string>(F.add); * adds('a', 'b'); * const add = F.memoize<((a: string, b: string) => string) | ((a: number, b: number) => number)>(F.add); * add('a', 'b') as string; * add(1, 2) as number; * ``` * * @param callFn */ export function memoize

(callFn: (...args: P) => R): (...args: P) => Promise>; export function memoize any>(callFn: F): (...args: Parameters) => Promise>>; /** * * * **Note** * - if use overloaded type function, use generic * ```ts * const addn = F.memoizeWithTimeout<(a: number, b: number) => number>(1, F.add); * addn(1, 2); * const adds = F.memoizeWithTimeout<(a: string, b: string) => string>(1, F.add); * adds('a', 'b'); * const add = F.memoizeWithTimeout<((a: string, b: string) => string) | ((a: number, b: number) => number)>(1, F.add); * add('a', 'b') as string; * add(1, 2) as number; * ``` * @param timeout timeout cache * @param callFn */ export function memoizeWithTimeout

(timeout: number, callFn: (...args: P) => (R | Promise)): (...args: P) => Promise; export function memoizeWithTimeout any>(timeout: number, callFn: F): (...args: Parameters) => Promise>>; export function memoizeWithTimeout

(timeout: number): (callFn: (...args: P) => (R | Promise)) => (...args: P) => Promise; export function memoizeWithTimeout any>(timeout: number): (callFn: F) => (...args: Parameters) => Promise>>; /** * https://github.com/rudty/nodekell#juxta * @param fn reduce function iterator * @param iter iterator */ // export function juxtA(fn: Iter>, iter: Iter>): Promise; export function juxtA, F extends FlatAccumulator>(fn: Iter, iter: T): Promise[]>; export function juxtA, F extends FlatAccumulator>(fn: Iter): (iter: T) => Promise[]>; // export function juxtA(fn: Iter>): (iter: Iter>) => Promise>>; /** * Similar `get`, get the value of an array element from an object or map. * * @example * const r0 = await juxtO(["A","C"], {A:1,B:2,C:3}); * console.log(r0); // print [1, 3] * * const r1 = await juxtO(["A","C"], {}); * console.log(r1); // print [undefined, undefined] * * const r2 = await juxtO(["A","C"], new Map([["A", 1], ["B", 2], ["C", 3]])); * console.log(r2); // print [1,2] * * @param key get array * @param target get obj or map */ export function juxtO(key: K[], target: T): Promise[]>; export function juxtO(key: K[], target: T): Promise[]>; export function juxtO(key: K[]): (target: T) => Promise[]>; export function juxtO(key: K[]): (target: T) => Promise[]>; export function juxtO(key: any[]): (target: any) => any[]; /** * return a random permutation of iterator * https://github.com/rudty/nodekell#shuffle * * @param iter any iterable * @return new shuffle Array */ export function shuffle(arr: ArrayLike): T[]; export function shuffle(iter: Iter): Promise; /** * return a random element * @param iter any iterable */ export function sample(arr: ArrayLike): T; export function sample(iter: Iter): Promise; export const _: any; export const underBar: any; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; export function match>(value: T, ...a: P): ReturnTypePickElements<1, P> | undefined; /** * * Create a new Map by combining the arguments of the function. * If the key exists, the value on the right is used. * * @example * const m1 = new Map([[1, 2], [3, 4]]); * const m2 = new Map([[5, 6], [7, 8]]); * const r1 = await F.mergeMap(m1, m2); * console.log(r1); // print Map { 1 => 2, 3 => 4, 5 => 6, 7 => 8 } * * const m3 = new Map([[1, 2], [3, 4]]); * const o1 = { 5: 6, 7: 8 }; * const r2 = await F.mergeMap(m3, o1); * console.log(r2); // print Map { 1 => 2, 3 => 4, '5' => 6, '7' => 8 } * * @param source1 source from which to copy properties * @param source2 source from which to copy properties */ export function mergeMap(source1: Iter<[K1, V1]>, source2: Iter<[K2, V2]>): Promise | ExtractPromise, ExtractPromise | ExtractPromise>>; export function mergeMap>(source1: T, source2: T, source3: T, ...sources: T[]): T extends Iter<[infer K, infer V]> ? Promise, ExtractPromise>> : Promise>; export function mergeMap(source1: any, source2: any, source3: any, ...sources: any[]): Promise>; export function mergeMap(source1: Iter<[K1, V1]>, source2: O1): Promise | string, ExtractPromise | ExtractPromise>>; export function mergeMap(source1: O1, source2: Map): Promise | string, ExtractPromise | ExtractPromise>>; export function mergeMap(source1: O1, source2: O2): Promise | ExtractPromise>>; export function mergeMap(source1: Map): (source2: object | Iter<[any, any]>, ...sources: (object | Iter<[any, any]>)[]) => Promise>; export function mergeMap(source1: object | Iter<[any, any]>): (source2: object | Iter<[any, any]>, ...sources: (object | Iter<[any, any]>)[]) => Promise>; /** * Create a new Map by combining the arguments of the function. * If the key exists, the value on the left is used. * * @example * const m1 = new Map([[1, 2], [3, 4]]); * const m2 = new Map([[5, 6], [7, 8]]); * const r1 = await F.mergeMapRight(m1, m2); * console.log(r1); // print Map { 5 => 6, 7 => 8, 1 => 2, 3 => 4 } * * const m2 = new Map([[1, 2], [3, 4]]); * const o2 = { 5: 6, 7: 8 }; * const r2 = await F.mergeMapRight(m2, o2); * console.log(r2); // Map { '5' => 6, '7' => 8, 1 => 2, 3 => 4 } * * @param source1 source from which to copy properties * @param source2 source from which to copy properties */ export function mergeMapRight(source1: Iter<[K1, V1]>, source2: Iter<[K2, V2]>): Promise | ExtractPromise, ExtractPromise | ExtractPromise>>; export function mergeMapRight>(source1: T, source2: T, source3: T, ...sources: T[]): T extends Iter<[infer K, infer V]> ? Promise, ExtractPromise>> : Promise>; export function mergeMapRight(source1: any, source2: any, source3: any, ...sources: any[]): Promise>; export function mergeMapRight(source1: Map, source2: O1): Promise | string, ExtractPromise | ExtractPromise>>; export function mergeMapRight(source1: O1, source2: Map): Promise | string, ExtractPromise | ExtractPromise>>; export function mergeMapRight(source1: O1, source2: O2): Promise | ExtractPromise>>; export function mergeMapRight(source1: Map): (source2: object | Iter<[any, any]>, ...sources: (object | Iter<[any, any]>)[]) => Promise>; export function mergeMapRight(source1: object | Iter<[any, any]>): (source2: object | Iter<[any, any]>, ...sources: (object | Iter<[any, any]>)[]) => Promise>; /** * Create a new object by combining the arguments of the function. * If the key exists, the value on the right is used. * * @example * const m1 = new Map([[1, 2], [3, 4]]); * const o1 = { 5: 6, 7: 8 }; * const r1 = await F.mergeObject(m1, o1); * console.log(r1); // print { '1': 2, '3': 4, '5': 6, '7': 8 } */ export function mergeObject(source1: Iter<[any, any]> | object, source2: Iter<[any, any]> | object, ...sources: (Iter<[any, any]> | object)[]): Promise; export function mergeObject(source1: Iter<[any, any]> | object): (source2: Iter<[any, any]> | object, ...sources: (Iter<[any, any]> | object)[]) => Promise; /** * Create a new object by combining the arguments of the function. * If the key exists, the value on the left is used. * * @example * const m1 = new Map([[1, 2], [3, 4]]); * const o1 = { 5: 6, 7: 8 }; * const r1 = await F.mergeObjectRight(m1, o1); * console.log(r1); // print { '1': 2, '3': 4, '5': 6, '7': 8 } * * @param source1 source from which to copy properties * @param source2 source from which to copy properties */ export function mergeObjectRight(source1: Iter<[any, any]> | object, source2: Iter<[any, any]> | object, ...sources: (Iter<[any, any]> | object)[]): Promise; export function mergeObjectRight(source1: Iter<[any, any]> | object): (source2: Iter<[any, any]> | object, ...sources: (Iter<[any, any]> | object)[]) => Promise; export type PairIterable = T extends Iter ? K extends [any, any] ? T : unknown : unknown; export type PairIterableKeyType = T extends Iter ? K extends any[] ? ExtractPromise : unknown : unknown; export type PairIterableValueType = T extends Iter ? K extends any[] ? ExtractPromise : unknown : unknown; /** * Gets only the Key value from the Collection object. * When an Iterable object traverses into an Array, returns an asynciterator that traverses only the first element. * @example * const m = new Map([["a", 1], ["b", 2]]); * for await(const k of F.keys(m)) { * console.log(k); * } * // print "a", "b" * * const a = async function *() { * yield [1, 2]; * yield [3, 4]; * yield [5, 6]; * }; * * for await (const e of F.keys(a())) { * console.log(e); * } * // print [1, 3, 5]s */ export function keys(iter: Iter<[K, any]>): AsyncIterable>; export function keys>(o: T): AsyncIterable>; export function keys(o: object): AsyncIterable; /** * Gets only the Value from the Collection object. * When an Iterable object traverses into an Array, returns an asynciterator that traverses only the second element. * @example * const m = new Map([["a", 1], ["b", 2]]); * for await(const k of F.values(m)) { * console.log(k); * } * // print * // 1 * // 2 * * const a = async function *() { * yield [1, 2]; * yield [3, 4]; * yield [5, 6]; * }; * * for await (const e of F.values(a())) { * console.log(e); * } * // print * // 2 * // 4 * // 6 */ export function values(iter: Iter<[any, V]>): AsyncIterable>; export function values>(o: T): AsyncIterable>; export function values(o: T): AsyncIterable; /** * It takes a value and a function and calls the function by value. * Pass the value to the first argument when calling the function. * * @example * const r = await F.doto({a: 1}, function () { * this.a = 3; * }); * * console.log(r); // print { a: 3 }; * * @param x value * @param fn1 function (this: T, x: T) => void */ export function doto(v: T, fn1: (this: T, v: T) => void): Promise; export function doto(v: T, fn1: (this: T, v: T) => void, ...fns: ((this: T, v: T) => void)[]): Promise;