import { wrapWithAbort } from './withabort.js'; /** * @ignore */ export async function createGrouping( source: AsyncIterable, keySelector: (value: TSource, signal?: AbortSignal) => TKey | Promise, elementSelector: (value: TSource, signal?: AbortSignal) => TValue | Promise, signal?: AbortSignal ): Promise> { const map = new Map(); for await (const item of wrapWithAbort(source, signal)) { const key = await keySelector(item, signal); let grouping = map.get(key); if (!map.has(key)) { grouping = []; map.set(key, grouping); } const element = await elementSelector(item, signal); grouping!.push(element); } return map; }