The type of input items
The type of output items after flattening
The function to transform each item into a data source. When the mapper returns undefined,
that value is filtered out and not included in the output stream.
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
A task that transforms and flattens items
In parallel mode, when an error occurs all pending operations are awaited (but not failed) before the error is thrown to prevent resource leaks.
// Synchronous mapper
await items([1, 2, 3])(flatMap(x => [x, x * 2]))(toArray());
// [1, 2, 2, 4, 3, 6]
// Async mapper for API calls
await items([1, 2, 3])(flatMap(async id => {
const response = await fetch(`/api/items/${id}`);
return response.json();
}))(toArray());
// Parallel processing
await items([1, 2, 3])(flatMap(async id => {
const data = await fetchData(id);
return data.items;
}, { parallel: true }))(toArray());
Creates a task that transforms each item into a data source and flattens the results.
Items are processed sequentially by default, preserving output order. In parallel mode, items are processed concurrently and flattened results are emitted as they complete without preserving order.
Data sources returned by the mapper are handled as follows:
undefined- filtered out and not included in the output streamThe mapper function can be synchronous or asynchronous (returning a Promise). Async mappers are useful for fetching data from APIs, databases, or any async source.