Skip to main content

asyncCollect

Callable


  • Collect the values from an AsyncTraversable and return them as an array.

    Example

    await asyncCollect([1, 2, 3])
    // => [2, 3, 4]

    await asyncCollect([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)])
    // => [2, 3, 4]

    await asyncCollect(asyncMap([1, 2, 3], (x) => x + 1))
    // => [2, 3, 4]

    const asyncFn = <T>(x: T) => Promise.resolve(x)
    async function* foobar() {
    yield await asyncFn('foo')
    yield await asyncFn('Bar')
    }
    await asyncCollect(asyncMap(foobar(), asyncFn))
    // => ["foo", "bar"]

    Alternatives

    Proposals


    Type parameters

    • T

      The element type.

    Parameters

    Returns Promise<T[]>

    An array with the values from the async generator.