@metreeca/pipe - v0.9.11
    Preparing search index...

    Function map

    • Creates a task that maps each input item to an output value using a mapper function.

      Items are processed sequentially by default, preserving output order. In parallel mode, items are processed concurrently and emitted as they complete without preserving order.

      Type Parameters

      • V

        The type of input values

      • R

        The type of mapped result values

      Parameters

      • mapper: (item: V) => R | Promise<R | undefined> | undefined

        The function to transform each item (can be sync or async). When the mapper returns undefined, that value is filtered out and not included in the output stream.

      • parallel: { parallel?: number | boolean } = {}

        Concurrency control: false/undefined/1 for sequential (default), true for parallel with auto-detected concurrency (CPU cores), 0 for unbounded concurrency (I/O-heavy tasks), or a number > 1 for explicit concurrency limit

      Returns Task<V, R>

      A task that transforms items using the mapper function

      In parallel mode, when an error occurs all pending operations are awaited (but not failed) before the error is thrown to prevent resource leaks.

      map((n: number) => n * 2)                                            // sequential
      map(async (id: string) => fetch(`/users/${id}`), { parallel: true }) // parallel (CPU cores)
      map(async (url: string) => fetch(url), { parallel: 0 }) // unbounded (I/O-heavy)
      map(heavyOperation, { parallel: 4 }) // parallel with limit