geninq
Version:
A JavaScript version of the Linq library for Generators
84 lines (83 loc) • 5.92 kB
TypeScript
import { Promised } from "./utils";
declare global {
interface Generator<T = unknown, TReturn = any, TNext = unknown> {
/**
* Groups the elements of a sequence according to a specified key selector function.
* @param builder A function to extract the key for each element.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey extends string | number | boolean, TElement = T, TResult = [TKey, Generator<TElement>]>(builder: (item: T) => TKey): Generator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a specified key selector function
* and projects the elements for each group by using a specified function.
* @param builder.key A function to extract the key for each element.
* @param builder.element A function to map each source element to an element in an grouping.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey extends string | number | boolean, TElement = T, TResult = [TKey, Generator<TElement>]>(builder: {
key: (item: T) => TKey;
element?: (item: T) => TElement;
}): Generator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a key selector function.
* The keys are compared by using a comparer and each group's elements are
* projected by using a specified function.
* @param builder.key A function to extract the key for each element.
* @param builder.element A function to map each source element to an element in an grouping.
* @param comparitor A comparitor function to compare keys with.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey, TElement = T, TResult = [TKey, Generator<TElement>]>(builder: {
key: (item: T) => TKey;
element?: (item: T) => TElement;
}, comparitor: (a: TKey, b: TKey) => boolean): Generator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a specified key selector
* function and compares the keys by using a specified comparer.
* @param builder A function to extract the key for each element.
* @param comparitor A comparitor function to compare keys with.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey, TElement = T, TResult = [TKey, Generator<TElement>]>(builder: (item: T) => TKey, comparitor: (a: TKey, b: TKey) => boolean): Generator<TResult, TReturn, TNext>;
}
interface AsyncGenerator<T = unknown, TReturn = any, TNext = unknown> {
/**
* Groups the elements of a sequence according to a specified key selector function.
* @param builder A function to extract the key for each element.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey extends string | number | boolean, TElement = T, TResult = [TKey, AsyncGenerator<TElement>]>(builder: (item: T) => Promised<TKey>): AsyncGenerator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a specified key selector function
* and projects the elements for each group by using a specified function.
* @param builder.key A function to extract the key for each element.
* @param builder.element A function to map each source element to an element in an grouping.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey extends string | number | boolean, TElement = T, TResult = [TKey, AsyncGenerator<TElement>]>(builder: {
key: (item: T) => Promised<TKey>;
element?: (item: T) => Promised<TElement>;
}): AsyncGenerator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a key selector function.
* The keys are compared by using a comparer and each group's elements are
* projected by using a specified function.
* @param builder.key A function to extract the key for each element.
* @param builder.element A function to map each source element to an element in an grouping.
* @param comparitor A comparitor function to compare keys with.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey, TElement = T, TResult = [TKey, AsyncGenerator<TElement>]>(builder: (item: T) => Promised<TKey>, comparitor: (a: TKey, b: TKey) => boolean): AsyncGenerator<TResult, TReturn, TNext>;
/**
* Groups the elements of a sequence according to a specified key selector
* function and compares the keys by using a specified comparer.
* @param builder A function to extract the key for each element.
* @param comparitor A comparitor function to compare keys with.
* @returns A collection of elements of the type specified where each element represents a projection over a group and its key.
*/
group_by<TKey, TElement = T, TResult = [TKey, AsyncGenerator<TElement>]>(builder: {
key: (item: T) => Promised<TKey>;
element?: (item: T) => Promised<TElement>;
}, comparitor: (a: TKey, b: TKey) => boolean): AsyncGenerator<TResult, TReturn, TNext>;
}
}