UNPKG

geninq

Version:

A JavaScript version of the Linq library for Generators

38 lines (37 loc) 2.25 kB
import { Promised } from "./utils"; declare global { interface Generator<T = unknown, TReturn = any, TNext = unknown> { /** * Creates a dictionary from a generator according to a * specified key selector function. * @param key_selector A function to extract a key from each element. * @returns A dictionary that contains values of type selected from the input sequence. */ dictionary<TKey extends number | string>(key_selector: (item: T) => TKey): Record<TKey, T>; /** * Creates a dictionary from a generator according to * specified key selector and element selector functions. * @param key_selector A function to extract a key from each element. * @param value_selector A transform function to produce a result element value from each element. * @returns A dictionary that contains values of type selected from the input sequence. */ dictionary<TKey extends number | string, TResult>(key_selector: (item: T) => TKey, value_selector: (item: T) => TResult): Record<TKey, TResult>; } interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> { /** * Creates a dictionary from a generator according to a * specified key selector function. * @param key_selector A function to extract a key from each element. * @returns A dictionary that contains values of type selected from the input sequence. */ dictionary<TKey extends number | string>(key_selector: (item: T) => Promised<TKey>): Promise<Record<TKey, T>>; /** * Creates a dictionary from a generator according to * specified key selector and element selector functions. * @param key_selector A function to extract a key from each element. * @param value_selector A transform function to produce a result element value from each element. * @returns A dictionary that contains values of type selected from the input sequence. */ dictionary<TKey extends number | string, TResult>(key_selector: (item: T) => Promised<TKey>, value_selector: (item: T) => Promised<TResult>): Promise<Record<TKey, TResult>>; } }