Add concat
.
This commit is contained in:
parent
1ba41d0f53
commit
46bb4c371b
3 changed files with 36 additions and 0 deletions
|
@ -15,6 +15,7 @@
|
||||||
- [Channel.from(callback | iterable | stream.Readable[, mapfn [, thisArg]]) -> read-only Channel](#channelfromcallback--iterable--streamreadable-mapfn--thisarg---read-only-channel)
|
- [Channel.from(callback | iterable | stream.Readable[, mapfn [, thisArg]]) -> read-only Channel](#channelfromcallback--iterable--streamreadable-mapfn--thisarg---read-only-channel)
|
||||||
- [Examples](#examples-1)
|
- [Examples](#examples-1)
|
||||||
- [Channel Object](#channel-object)
|
- [Channel Object](#channel-object)
|
||||||
|
- [concat(...arguments) -> Channel](#concatarguments---channel)
|
||||||
- [every(callbackfn[, thisArg]) -> async Boolean](#everycallbackfn-thisarg---async-boolean)
|
- [every(callbackfn[, thisArg]) -> async Boolean](#everycallbackfn-thisarg---async-boolean)
|
||||||
- [filter(callbackfn[, thisArg]) -> Channel](#filtercallbackfn-thisarg---channel)
|
- [filter(callbackfn[, thisArg]) -> Channel](#filtercallbackfn-thisarg---channel)
|
||||||
- [forEach(callbackfn[, thisArg]) -> async](#foreachcallbackfn-thisarg---async)
|
- [forEach(callbackfn[, thisArg]) -> async](#foreachcallbackfn-thisarg---async)
|
||||||
|
@ -202,6 +203,12 @@ const fromStream = Channel.from(
|
||||||
|
|
||||||
## Channel Object
|
## Channel Object
|
||||||
|
|
||||||
|
### concat(...arguments) -> Channel
|
||||||
|
|
||||||
|
When the `concat` method is called with zero or more arguments, it returns a
|
||||||
|
channel containing the values of the channel followed by the channel values of
|
||||||
|
each argument in order.
|
||||||
|
|
||||||
### every(callbackfn[, thisArg]) -> async Boolean
|
### every(callbackfn[, thisArg]) -> async Boolean
|
||||||
|
|
||||||
`callbackfn` should be a function that accepts one argument and returns a value
|
`callbackfn` should be a function that accepts one argument and returns a value
|
||||||
|
|
20
lib/index.js
20
lib/index.js
|
@ -103,6 +103,26 @@ const Channel = function(length = 0) {
|
||||||
|
|
||||||
const readOnly = Object.freeze(
|
const readOnly = Object.freeze(
|
||||||
Object.assign(Object.create(prototype), {
|
Object.assign(Object.create(prototype), {
|
||||||
|
concat: (...args) => {
|
||||||
|
const output = Channel();
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
await readOnly.forEach(output.push);
|
||||||
|
|
||||||
|
for (let index = 0; index < args.length; index++) {
|
||||||
|
const arg = args[index];
|
||||||
|
|
||||||
|
await (Channel.isChannel(arg)
|
||||||
|
? arg.forEach(output.push)
|
||||||
|
: output.push(arg));
|
||||||
|
}
|
||||||
|
|
||||||
|
output.close();
|
||||||
|
})();
|
||||||
|
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
every: async (callbackfn, thisArg) => {
|
every: async (callbackfn, thisArg) => {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const value = await readOnly.shift();
|
const value = await readOnly.shift();
|
||||||
|
|
|
@ -213,6 +213,15 @@ describe(`Channel object`, function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`concat`, async function() {
|
||||||
|
assert.deepEqual(
|
||||||
|
await Channel.of(0, 1, 2)
|
||||||
|
.concat(Channel.of(3, 4, 5), 6)
|
||||||
|
.values(),
|
||||||
|
[0, 1, 2, 3, 4, 5, 6]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it(`every`, async function() {
|
it(`every`, async function() {
|
||||||
const even = number => number % 2 === 0;
|
const even = number => number % 2 === 0;
|
||||||
assert(!await Channel.of(0, 1, 2).every(even));
|
assert(!await Channel.of(0, 1, 2).every(even));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue