@@ -1918,7 +1918,7 @@ import { Resolver } from 'dns/promises';
19181918await Readable .from ([1 , 2 , 3 , 4 ]).toArray (); // [1, 2, 3, 4]
19191919
19201920// Make dns queries concurrently using .map and collect
1921- // the results into an aray using toArray
1921+ // the results into an array using toArray
19221922const dnsResults = await Readable .from ([
19231923 ' nodejs.org' ,
19241924 ' openjsf.org' ,
@@ -1929,6 +1929,104 @@ const dnsResults = await Readable.from([
19291929}, { concurrency: 2 }).toArray ();
19301930```
19311931
1932+ ### ` readable.some(fn[, options]) `
1933+
1934+ <!-- YAML
1935+ added: REPLACEME
1936+ -->
1937+
1938+ > Stability: 1 - Experimental
1939+
1940+ * ` fn ` {Function|AsyncFunction} a function to call on each item of the stream.
1941+ * ` data ` {any} a chunk of data from the stream.
1942+ * ` options ` {Object}
1943+ * ` signal ` {AbortSignal} aborted if the stream is destroyed allowing to
1944+ abort the ` fn ` call early.
1945+ * ` options ` {Object}
1946+ * ` concurrency ` {number} the maximum concurrent invocation of ` fn ` to call
1947+ on the stream at once. ** Default:** ` 1 ` .
1948+ * ` signal ` {AbortSignal} allows destroying the stream if the signal is
1949+ aborted.
1950+ * Returns: {Promise} a promise evaluating to ` true ` if ` fn ` returned a truthy
1951+ value for at least one of the chunks.
1952+
1953+ This method is similar to ` Array.prototype.some ` and calls ` fn ` on each chunk
1954+ in the stream until the awaited return value is ` true ` (or any truthy value).
1955+ Once an ` fn ` call on a chunk awaited return value is truthy, the stream is
1956+ destroyed and the promise is fulfilled with ` true ` . If none of the ` fn `
1957+ calls on the chunks return a truthy value, the promise is fulfilled with
1958+ ` false ` .
1959+
1960+ ``` mjs
1961+ import { Readable } from ' stream' ;
1962+ import { stat } from ' fs/promises' ;
1963+
1964+ // With a synchronous predicate.
1965+ await Readable .from ([1 , 2 , 3 , 4 ]).some ((x ) => x > 2 ); // true
1966+ await Readable .from ([1 , 2 , 3 , 4 ]).some ((x ) => x < 0 ); // false
1967+
1968+ // With an asynchronous predicate, making at most 2 file checks at a time.
1969+ const anyBigFile = await Readable .from ([
1970+ ' file1' ,
1971+ ' file2' ,
1972+ ' file3' ,
1973+ ]).some (async (fileName ) => {
1974+ const stats = await stat (fileName);
1975+ return stat .size > 1024 * 1024 ;
1976+ }, { concurrency: 2 });
1977+ console .log (anyBigFile); // `true` if any file in the list is bigger than 1MB
1978+ console .log (' done' ); // Stream has finished
1979+ ```
1980+
1981+ ### ` readable.every(fn[, options]) `
1982+
1983+ <!-- YAML
1984+ added: REPLACEME
1985+ -->
1986+
1987+ > Stability: 1 - Experimental
1988+
1989+ * ` fn ` {Function|AsyncFunction} a function to call on each item of the stream.
1990+ * ` data ` {any} a chunk of data from the stream.
1991+ * ` options ` {Object}
1992+ * ` signal ` {AbortSignal} aborted if the stream is destroyed allowing to
1993+ abort the ` fn ` call early.
1994+ * ` options ` {Object}
1995+ * ` concurrency ` {number} the maximum concurrent invocation of ` fn ` to call
1996+ on the stream at once. ** Default:** ` 1 ` .
1997+ * ` signal ` {AbortSignal} allows destroying the stream if the signal is
1998+ aborted.
1999+ * Returns: {Promise} a promise evaluating to ` true ` if ` fn ` returned a truthy
2000+ value for all of the chunks.
2001+
2002+ This method is similar to ` Array.prototype.every ` and calls ` fn ` on each chunk
2003+ in the stream to check if all awaited return values are truthy value for ` fn ` .
2004+ Once an ` fn ` call on a chunk awaited return value is falsy, the stream is
2005+ destroyed and the promise is fulfilled with ` false ` . If all of the ` fn ` calls
2006+ on the chunks return a truthy value, the promise is fulfilled with ` true ` .
2007+
2008+ ``` mjs
2009+ import { Readable } from ' stream' ;
2010+ import { stat } from ' fs/promises' ;
2011+
2012+ // With a synchronous predicate.
2013+ await Readable .from ([1 , 2 , 3 , 4 ]).every ((x ) => x > 2 ); // false
2014+ await Readable .from ([1 , 2 , 3 , 4 ]).every ((x ) => x > 0 ); // true
2015+
2016+ // With an asynchronous predicate, making at most 2 file checks at a time.
2017+ const allBigFiles = await Readable .from ([
2018+ ' file1' ,
2019+ ' file2' ,
2020+ ' file3' ,
2021+ ]).every (async (fileName ) => {
2022+ const stats = await stat (fileName);
2023+ return stat .size > 1024 * 1024 ;
2024+ }, { concurrency: 2 });
2025+ // `true` if all files in the list are bigger than 1MiB
2026+ console .log (allBigFiles);
2027+ console .log (' done' ); // Stream has finished
2028+ ```
2029+
19322030### Duplex and transform streams
19332031
19342032#### Class: ` stream.Duplex `
0 commit comments