From 71da0944228340ea486117bdcf2467faf7ecd657 Mon Sep 17 00:00:00 2001 From: David <> Date: Mon, 8 Feb 2021 16:34:29 -0600 Subject: [PATCH] Rewrite `map`. --- lib/index.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/index.js b/lib/index.js index 63ae469..4917e19 100644 --- a/lib/index.js +++ b/lib/index.js @@ -182,19 +182,10 @@ const Channel = function(length = 0) { join: async (separator) => (await readOnly.values()).join(separator), - map: (callbackfn, thisArg) => { - const output = Channel(); - - (async () => { - await readOnly.forEach((value) => - output.push(callbackfn.call(thisArg, value)) - ); - - await output.close(); - })(); - - return output; - }, + map: (callbackfn, thisArg) => + readOnly.flatMap((value) => + Channel.of(callbackfn.call(thisArg, value)) + ), readOnly: () => readOnly,