Function map

  • Standard Array.map logic for the iterable, extended for supporting iteration state.

    When the callback is asynchronous, the operator does not resolve the value, to give you the flexibility of resolving it in a variety of ways:

    • you can follow it up with operator wait, for sequential resolution
    • you can follow it up with operator waitRace, to emit values as they resolve
    • you can follow it up with aggregate + Promise.all, for a grouped resolution
    • you can follow it up with aggregate + Promise.race, for a grouped race-resolution
    • you can provide any custom resolution logic
    import {pipeAsync, map, wait} from 'iter-ops';

    const i = pipeAsync(
    [1, 2, 3],
    map(async a => {
    const res1 = await firstAsyncRequest(a);
    const res2 = await secondAsyncRequest(a);
    return {res1, res2};
    }),
    wait() // resolve sequentially
    );

    for await (const a of i) {
    console.log(a); // prints data from {res1, res2}
    }

    Type Parameters

    • T

    • R

    Parameters

    • cb: ((value, index, state) => R)
        • (value, index, state): R
        • Parameters

          Returns R

    Returns Operation<T, R>