Last active
February 10, 2020 02:13
-
-
Save mattpodwysocki/edd6af8f1a297fe1fd71b352ab526f95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface GroupByOptions<TSource, TKey, TValue = TSource> { | |
keySelector: (value: TSource) => TKey | Promise<TKey>; | |
elementSelector?: (value: TSource) => TValue | Promise<TValue>; | |
signal?: AbortSignal; | |
} | |
export interface GroupByOptionsWithSelector<TSource, TKey, TValue, TResult> { | |
keySelector: (value: TSource) => TKey | Promise<TKey>; | |
elementSelector?: (value: TSource) => TValue | Promise<TValue>; | |
resultSelector?: ( | |
key: TKey, | |
values: Iterable<TValue> | |
) => TResult | Promise<TResult>; | |
signal?: AbortSignal; | |
} | |
export function groupBy<TSource, TKey>( | |
options: GroupByOptions<TSource, TKey, TSource> | |
): OperatorAsyncFunction<TSource, GroupedAsyncIterable<TKey, TSource>>; | |
export function groupBy<TSource, TKey, TValue>( | |
options: GroupByOptions<TSource, TKey, TValue> | |
): OperatorAsyncFunction<TSource, GroupedAsyncIterable<TKey, TValue>>; | |
export function groupBy<TSource, TKey, TValue, TResult>( | |
options: GroupByOptionsWithSelector<TSource, TKey, TValue, TResult> | |
): OperatorAsyncFunction<TSource, TResult> { | |
return function groupByOperatorFunction(source: AsyncIterable<TSource>): AsyncIterableX<TResult> { | |
return new GroupByAsyncIterable<TSource, TKey, TValue, TResult>( | |
source, | |
options?.keySelector, | |
options?.elementSelector || identityAsync, | |
options?.resultSelector || groupByResultIdentityAsync | |
); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function groupBy<TSource, TKey>( | |
keySelector: (value: TSource) => TKey | Promise<TKey> | |
): OperatorAsyncFunction<TSource, GroupedAsyncIterable<TKey, TSource>>; | |
export function groupBy<TSource, TKey, TValue>( | |
keySelector: (value: TSource) => TKey | Promise<TKey>, | |
elementSelector?: (value: TSource) => TValue | Promise<TValue> | |
): OperatorAsyncFunction<TSource, GroupedAsyncIterable<TKey, TValue>>; | |
export function groupBy<TSource, TKey, TValue, TResult>( | |
keySelector: (value: TSource) => TKey | Promise<TKey>, | |
elementSelector?: (value: TSource) => TValue | Promise<TValue>, | |
resultSelector?: (key: TKey, values: Iterable<TValue>) => TResult | Promise<TResult> | |
): OperatorAsyncFunction<TSource, TResult>; | |
export function groupBy<TSource, TKey, TValue, TResult>( | |
keySelector: (value: TSource) => TKey | Promise<TKey>, | |
elementSelector: (value: TSource) => TValue | Promise<TValue> = identityAsync, | |
resultSelector: ( | |
key: TKey, | |
values: Iterable<TValue> | |
) => TResult | Promise<TResult> = groupByResultIdentityAsync | |
): OperatorAsyncFunction<TSource, TResult> { | |
return function groupByOperatorFunction(source: AsyncIterable<TSource>): AsyncIterableX<TResult> { | |
return new GroupByAsyncIterable<TSource, TKey, TValue, TResult>( | |
source, | |
keySelector, | |
elementSelector, | |
resultSelector | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment