Function to apply to each value, receiving the value, its index, and worker number
Configuration options
Optionalconcurrency?: numberNumber of concurrent operations (default: 1)
OptionalpreserveOrder?: booleanWhether to preserve the original order (default: true)
Optionalsignal?: AbortSignalAborting makes the transformer throw signal.reason and stop pulling from
the source; a mapping already in flight is left to settle on its own and its result is dropped
A transformer function that yields the mapped values
Applies a mapping function to each value in an async iterable, with support for concurrent processing and order preservation.
// Serial mapping (default)
const doubled = await G.pipe(
G.ofIterable([1, 2, 3]),
G.map(x => x * 2),
G.array
); // [2, 4, 6]
// Concurrent mapping with preserved order
const results = await G.pipe(
G.ofIterable([1, 2, 3, 4, 5]),
G.map(async x => {
await sleep(100);
return x * 2;
}, { concurrency: 3 }),
G.array
); // [2, 4, 6, 8, 10]
Creates a transformer that maps each value using the provided function.