Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2022-01-20 15:01:43 +0300
committerBenjamin Gruenbaum <benjamingr@gmail.com>2022-01-23 11:13:17 +0300
commitcc8931a91690e559fbbc323eb7c7436a575f922f (patch)
tree800ba9c85f4ac5131d72d11537ef9e2663d64b7f /lib
parent68bb83f11bcd57827dcff4f65c31336466eec72b (diff)
stream: support flatMap
Support the `flatMap` method from the iterator helper TC39 proposal on readable streams. Co-Authored-By: Robert Nagy <ronagy@icloud.com> PR-URL: https://github.com/nodejs/node/pull/41612 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/streams/operators.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/internal/streams/operators.js b/lib/internal/streams/operators.js
index 9c50865f3da..1218942b641 100644
--- a/lib/internal/streams/operators.js
+++ b/lib/internal/streams/operators.js
@@ -229,8 +229,16 @@ async function toArray(options) {
}
return result;
}
+
+async function* flatMap(fn, options) {
+ for await (const val of this.map(fn, options)) {
+ yield* val;
+ }
+}
+
module.exports.streamReturningOperators = {
filter,
+ flatMap,
map,
};