import { Mapper } from 'augmentative-iterable'; import { AsyncReducer, ItemType, Reducer } from '../base'; import { BaseChainKeyType, Indexes } from './to-object-chain-function'; export type ToMapChainKey = keyof T | Mapper; export type ToMapChainValueOf> = K extends Mapper ? ReturnType : K extends keyof V ? V[K] : never; export type MapChain>, V, R = V[], Pos extends number = 0> = { done: R; any: any; recur: ToMapChainValueOf extends BaseChainKeyType ? Map, MapChain> : ToMapChainValueOf extends Iterable ? Map>, MapChain> : never; }[Pos extends Arr['length'] ? 'done' : Pos extends -1 ? 'any' : 'recur']; export interface ToMapChainFunction { /** * Creates an map chain with the values of the specified fields where the latest * value in the chain will be the iterable item itself. This is a resolving operation * @param keys The keys to be chained * @returns The object chain */ >>(...keys: A): MapChain; } export interface AsyncToMapChainFunction { /** * Creates an map chain with the values of the specified fields where the latest * value in the chain will be the iterable item itself. This is a resolving operation * @param keys The keys to be chained. It can be either property names or mapping functions * @returns The object chain */ >>(...keys: A): Promise>; } export interface ToMapChainReduceFunction { /** * Creates an map chain with the values of the specified fields where the latest * value in the chain will be the iterable item itself. This is a resolving operation * @param initial An initializer function to define the base value for each leaf * @param reduce: A reduce function to accumulate the leaf value for each value that fits it * @param keys The keys to be chained. It can be either property names or mapping functions * @returns The object chain */ >, R>(initial: () => R, reduce: Reducer, ...keys: A): MapChain; } export interface AsyncToMapChainReduceFunction { /** * Creates an map chain with the values of the specified fields where the latest * value in the chain will be the iterable item itself. This is a resolving operation * @param initial An initializer function to define the base value for each leaf * @param reduce: A reduce function to accumulate the leaf value for each value that fits it * @param keys The keys to be chained. It can be either property names or mapping functions * @returns The object chain */ >, R>(initial: () => R, reduce: AsyncReducer, ...keys: A): Promise>; }