@@ -1864,7 +1864,7 @@ import { Resolver } from 'dns/promises';
1864
1864
await Readable .from ([1 , 2 , 3 , 4 ]).toArray (); // [1, 2, 3, 4]
1865
1865
1866
1866
// Make dns queries concurrently using .map and collect
1867
- // the results into an aray using toArray
1867
+ // the results into an array using toArray
1868
1868
const dnsResults = await Readable .from ([
1869
1869
' nodejs.org' ,
1870
1870
' openjsf.org' ,
@@ -1875,6 +1875,104 @@ const dnsResults = await Readable.from([
1875
1875
}, { concurrency: 2 }).toArray ();
1876
1876
```
1877
1877
1878
+ ### ` readable.some(fn[, options]) `
1879
+
1880
+ <!-- YAML
1881
+ added: REPLACEME
1882
+ -->
1883
+
1884
+ > Stability: 1 - Experimental
1885
+
1886
+ * ` fn ` {Function|AsyncFunction} a function to call on each item of the stream.
1887
+ * ` data ` {any} a chunk of data from the stream.
1888
+ * ` options ` {Object}
1889
+ * ` signal ` {AbortSignal} aborted if the stream is destroyed allowing to
1890
+ abort the ` fn ` call early.
1891
+ * ` options ` {Object}
1892
+ * ` concurrency ` {number} the maximum concurrent invocation of ` fn ` to call
1893
+ on the stream at once. ** Default:** ` 1 ` .
1894
+ * ` signal ` {AbortSignal} allows destroying the stream if the signal is
1895
+ aborted.
1896
+ * Returns: {Promise} a promise evaluating to ` true ` if ` fn ` returned a truthy
1897
+ value for at least one of the chunks.
1898
+
1899
+ This method is similar to ` Array.prototype.some ` and calls ` fn ` on each chunk
1900
+ in the stream until the awaited return value is ` true ` (or any truthy value).
1901
+ Once an ` fn ` call on a chunk awaited return value is truthy, the stream is
1902
+ destroyed and the promise is fulfilled with ` true ` . If none of the ` fn `
1903
+ calls on the chunks return a truthy value, the promise is fulfilled with
1904
+ ` false ` .
1905
+
1906
+ ``` mjs
1907
+ import { Readable } from ' stream' ;
1908
+ import { stat } from ' fs/promises' ;
1909
+
1910
+ // With a synchronous predicate.
1911
+ await Readable .from ([1 , 2 , 3 , 4 ]).some ((x ) => x > 2 ); // true
1912
+ await Readable .from ([1 , 2 , 3 , 4 ]).some ((x ) => x < 0 ); // false
1913
+
1914
+ // With an asynchronous predicate, making at most 2 file checks at a time.
1915
+ const anyBigFile = await Readable .from ([
1916
+ ' file1' ,
1917
+ ' file2' ,
1918
+ ' file3' ,
1919
+ ]).some (async (fileName ) => {
1920
+ const stats = await stat (fileName);
1921
+ return stat .size > 1024 * 1024 ;
1922
+ }, { concurrency: 2 });
1923
+ console .log (anyBigFile); // `true` if any file in the list is bigger than 1MB
1924
+ console .log (' done' ); // Stream has finished
1925
+ ```
1926
+
1927
+ ### ` readable.every(fn[, options]) `
1928
+
1929
+ <!-- YAML
1930
+ added: REPLACEME
1931
+ -->
1932
+
1933
+ > Stability: 1 - Experimental
1934
+
1935
+ * ` fn ` {Function|AsyncFunction} a function to call on each item of the stream.
1936
+ * ` data ` {any} a chunk of data from the stream.
1937
+ * ` options ` {Object}
1938
+ * ` signal ` {AbortSignal} aborted if the stream is destroyed allowing to
1939
+ abort the ` fn ` call early.
1940
+ * ` options ` {Object}
1941
+ * ` concurrency ` {number} the maximum concurrent invocation of ` fn ` to call
1942
+ on the stream at once. ** Default:** ` 1 ` .
1943
+ * ` signal ` {AbortSignal} allows destroying the stream if the signal is
1944
+ aborted.
1945
+ * Returns: {Promise} a promise evaluating to ` true ` if ` fn ` returned a truthy
1946
+ value for all of the chunks.
1947
+
1948
+ This method is similar to ` Array.prototype.every ` and calls ` fn ` on each chunk
1949
+ in the stream to check if all awaited return values are truthy value for ` fn ` .
1950
+ Once an ` fn ` call on a chunk awaited return value is falsy, the stream is
1951
+ destroyed and the promise is fulfilled with ` false ` . If all of the ` fn ` calls
1952
+ on the chunks return a truthy value, the promise is fulfilled with ` true ` .
1953
+
1954
+ ``` mjs
1955
+ import { Readable } from ' stream' ;
1956
+ import { stat } from ' fs/promises' ;
1957
+
1958
+ // With a synchronous predicate.
1959
+ await Readable .from ([1 , 2 , 3 , 4 ]).every ((x ) => x > 2 ); // false
1960
+ await Readable .from ([1 , 2 , 3 , 4 ]).every ((x ) => x > 0 ); // true
1961
+
1962
+ // With an asynchronous predicate, making at most 2 file checks at a time.
1963
+ const allBigFiles = await Readable .from ([
1964
+ ' file1' ,
1965
+ ' file2' ,
1966
+ ' file3' ,
1967
+ ]).every (async (fileName ) => {
1968
+ const stats = await stat (fileName);
1969
+ return stat .size > 1024 * 1024 ;
1970
+ }, { concurrency: 2 });
1971
+ // `true` if all files in the list are bigger than 1MiB
1972
+ console .log (allBigFiles);
1973
+ console .log (' done' ); // Stream has finished
1974
+ ```
1975
+
1878
1976
### Duplex and transform streams
1879
1977
1880
1978
#### Class: ` stream.Duplex `
0 commit comments