Documentation / @agentick/kernel / mapStream
Function: mapStream() ​
mapStream<
T,R>(stream,mapper):AsyncIterable<R>
Defined in: 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 ​
T ​
T
Input item type
R ​
R
Output item type
Parameters ​
stream ​
AsyncIterable<T>
Source async iterable
mapper ​
(item) => 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);
});