AIDK API Reference / aidk-kernel / mapStream
Function: mapStream() ​
ts
function mapStream<T, R>(stream: AsyncIterable<T>, mapper: (item: T) => R | Promise<R>): AsyncIterable<R>;Defined in: packages/kernel/src/stream.ts:48
Transform items in an async stream using a mapper function.
Preserves the current execution context through all iterations.
Type Parameters ​
| Type Parameter | Description |
|---|---|
T | Input item type |
R | Output item type |
Parameters ​
| Parameter | Type | Description |
|---|---|---|
stream | AsyncIterable<T> | Source async iterable |
mapper | (item: T) => R | Promise<R> | Function to transform each item |
Returns ​
AsyncIterable<R>
Async iterable of transformed items
Examples ​
typescript
const numbers = getNumberStream();
const doubled = mapStream(numbers, (n) => n * 2);
for await (const n of doubled) {
console.log(n);
}typescript
const users = mapStream(userIds, async (id) => {
return await fetchUser(id);
});