Rewrite filter.

This commit is contained in:
David 2021-02-08 16:29:32 -06:00
parent 35df66ce79
commit ed06cb080e
2 changed files with 5 additions and 16 deletions

View file

@ -140,21 +140,10 @@ const Channel = function(length = 0) {
}
},
filter: (callbackfn, thisArg) => {
const output = Channel();
(async () => {
await readOnly.forEach(async (value) => {
if (await callbackfn.call(thisArg, value)) {
await output.push(value);
}
});
await output.close();
})();
return output;
},
filter: (callbackfn, thisArg) =>
readOnly.flatMap((value) =>
callbackfn.call(thisArg, value) ? Channel.of(value) : Channel.of()
),
flat: (depth) =>
readOnly.flatMap((value) =>