diff --git a/doc/api/stream.md b/doc/api/stream.md index 3a3c0b053aacbe..cd7c1015491a34 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -1679,6 +1679,41 @@ option. In the code example above, data will be in a single chunk if the file has less then 64 KiB of data because no `highWaterMark` option is provided to [`fs.createReadStream()`][]. +##### `readable.compose(stream[, options])` + + + +> Stability: 1 - Experimental + +* `stream` {Stream|Iterable|AsyncIterable|Function} +* `options` {Object} + * `signal` {AbortSignal} allows destroying the stream if the signal is + aborted. +* Returns: {Duplex} a stream composed with the stream `stream`. + +```mjs +import { Readable } from 'node:stream'; + +async function* splitToWords(source) { + for await (const chunk of source) { + const words = String(chunk).split(' '); + + for (const word of words) { + yield word; + } + } +} + +const wordsStream = Readable.from(['this is', 'compose as operator']).compose(splitToWords); +const words = await wordsStream.toArray(); + +console.log(words); // prints ['this', 'is', 'compose', 'as', 'operator'] +``` + +See [`stream.compose`][] for more information. + ##### `readable.iterator([options])`