import { AsyncOperator } from '../../AsyncSeq'; /** * Returns a sequence grouped by a specified key. * * ```typescript * const source1 = [ * {groupKey: 1, value: "test1"}, * {groupKey: 3, value: "test2"}, * {groupKey: 1, value: "test3"}, * {groupKey: 1, value: "test4"}, * {groupKey: 3, value: "test5"}, * {groupKey: 2, value: "test6"} * ] * * const result1 = await fromAsAsync(source1).pipe( * groupByAsync(async one => one.groupKey) * ).toArrayAsync(); * * * // result1: [ * // {key: 1, values: [ * // {groupKey: 1, value: "test1"}, * // {groupKey: 1, value: "test3"}, * // {groupKey: 1, value: "test4"} * // ]}, * // {key: 3, values: [ * // {groupKey: 3, value: "test2"}, * // {groupKey: 3, value: "test5"} * // ]}, * // {key: 2, values: [ * // {groupKey: 2, value: "test6"} * // ]} * // ] * * const source2 = [ * {groupKey: {key: 1}, value: "test1"}, * {groupKey: {key: 2}, value: "test2"}, * {groupKey: {key: 1}, value: "test3"}, * {groupKey: {key: 1}, value: "test4"}, * ] * * const result2 = await fromAsAsync(source2).pipe( * groupByAsync( * async one => one.groupKey, * async one => one.value, * async k => k.key * )).toArrayAsync(); * * // result2: [ * // {key: {key: 1}, values: ["test1","test3","test4"]}, * // {key: {key: 2}, values: ["test2"]} * // ]; * ``` * * For more information on *keySelector* and *comparableValueForKey*, please refer to [Equality Strategy](/#equality-strategy). * * The implementation of *asyncDefaultSelector* is as follows. * ```typescript * export const asyncDefaultSelector = (target: any): any => Promise.resolve(target); * ``` * * @param target Sequence to be removed. * @param keySelector Function to return the object used to check Equality.. * @param elementSelector Function to return the object to be enumerated in the Value property of the grouped result. * @param comparableValueForKey This function returns an object that is unique to the key selected by *keySelector*. * It is recommended to return a string or number. * @returns Operator function. * @typeParam T Source element type. * @typeParam TValue The type that will be enumerated in the Value property of the grouped result. * @typeParam TKey key type. * @typeParam TComparableValue The type of the return value returned by *comparableValueForKey*. * @category Async Operators */ export declare const groupByAsync: (keySelector: (target: T) => Promise, elementSelector?: (target: T) => Promise, comparableValueForKey?: ((key: TKey) => Promise) | undefined) => AsyncOperator;