Rewrite filter
.
This commit is contained in:
parent
35df66ce79
commit
ed06cb080e
2 changed files with 5 additions and 16 deletions
19
lib/index.js
19
lib/index.js
|
@ -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) =>
|
||||
|
|
|
@ -250,7 +250,7 @@ describe(`Channel object`, function() {
|
|||
it(`filter`, async function() {
|
||||
assert.deepEqual(
|
||||
await Channel.of(0, 1, 2, 3, 4, 5)
|
||||
.filter(async (value) => value % 2 !== 0)
|
||||
.filter((value) => value % 2 !== 0)
|
||||
.values(),
|
||||
[1, 3, 5]
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue