collect
Call Signature
Section titled “Call Signature”function collect<T>(source): Promise<T[]>;Defined in: collect.ts:26
Collect all values from an iterable into an array.
Sync/async adaptive: an AsyncIterable returns a Promise<T[]>, a sync
Iterable returns T[] directly — no await needed (and await still
works on both).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
AsyncIterable<T> |
Returns
Section titled “Returns”Promise<T[]>
Examples
Section titled “Examples”Async source
async function* gen() { yield 1; yield 2;}
const values = await collect(gen()); // [1, 2]Sync source — result is immediate
const values = collect(new Set([1, 2])); // [1, 2], no awaitCall Signature
Section titled “Call Signature”function collect<T>(source): T[];Defined in: collect.ts:27
Collect all values from an iterable into an array.
Sync/async adaptive: an AsyncIterable returns a Promise<T[]>, a sync
Iterable returns T[] directly — no await needed (and await still
works on both).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
Iterable<T> |
Returns
Section titled “Returns”T[]
Examples
Section titled “Examples”Async source
async function* gen() { yield 1; yield 2;}
const values = await collect(gen()); // [1, 2]Sync source — result is immediate
const values = collect(new Set([1, 2])); // [1, 2], no awaitCall Signature
Section titled “Call Signature”function collect<T>(source): MaybePromise<T[]>;Defined in: collect.ts:28
Collect all values from an iterable into an array.
Sync/async adaptive: an AsyncIterable returns a Promise<T[]>, a sync
Iterable returns T[] directly — no await needed (and await still
works on both).
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
source |
AsyncIterable<T, any, any> | Iterable<T, any, any> |
Returns
Section titled “Returns”MaybePromise<T[]>
Examples
Section titled “Examples”Async source
async function* gen() { yield 1; yield 2;}
const values = await collect(gen()); // [1, 2]Sync source — result is immediate
const values = collect(new Set([1, 2])); // [1, 2], no await