Input chunk type
Output chunk type
ReadableStream with transformed chunks
const numberStream = getNumberStream();
const doubled = streamMap(numberStream, {
Map: (n) => n * 2,
Close: () => console.log('Stream ended')
});
// Async transformation
const enriched = streamMap(userStream, {
Map: async (user) => {
const details = await fetchUserDetails(user.id);
return { ...user, ...details };
}
});
Transforms a ReadableStream by applying a mapping function to each chunk.
Similar to Array.map() but for streams. Supports both sync and async mapping functions. Calls optional Close callback when stream ends.