UNPKG

1.5 kBTypeScriptView Raw
1/**
2 * The options for the toMap method which include an optional element selector and abort signal for cancellation.
3 *
4 * @interface ToMapOptions
5 * @template TSource
6 * @template TElement
7 */
8export interface ToMapOptions<TSource, TElement> {
9 /**
10 * The selector to get the key for the map.
11 *
12 * @memberof ToMapOptions
13 */
14 keySelector: (item: TSource, signal?: AbortSignal) => TElement | Promise<TElement>;
15 /**
16 * The selector used to get the element for the Map.
17 *
18 * @memberof ToMapOptions
19 */
20 elementSelector?: (item: TSource, signal?: AbortSignal) => TElement | Promise<TElement>;
21 /**
22 * An optional abort signal to cancel the operation at any time.
23 *
24 * @type {AbortSignal}
25 * @memberof ToMapOptions
26 */
27 signal?: AbortSignal;
28}
29/**
30 * Converts an async-iterable to a map with a key selector and options for an element selector and cancellation.
31 *
32 * @export
33 * @template TSource The type of elements in the source collection.
34 * @template TKey The type of key used for the map.
35 * @template TElement The type of element to use for the map.
36 * @param {AsyncIterable<TSource>} source The source collection to turn into a map.
37 * @param {ToMapOptions<TSource, TElement>} [options]
38 * @returns {(Promise<Map<TKey, TElement | TSource>>)}
39 */
40export declare function toMap<TSource, TKey, TElement = TSource>(source: AsyncIterable<TSource>, options: ToMapOptions<TSource, TElement>): Promise<Map<TKey, TElement | TSource>>;