Add length
.
This commit is contained in:
parent
3af150ae49
commit
a0a68ab8d1
3 changed files with 14 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
||||||
- [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)
|
||||||
- [join(separator) -> async String](#joinseparator---async-string)
|
- [join(separator) -> async String](#joinseparator---async-string)
|
||||||
|
- [length](#length)
|
||||||
- [map(callbackfn[, thisArg]) -> Channel](#mapcallbackfn-thisarg---channel)
|
- [map(callbackfn[, thisArg]) -> Channel](#mapcallbackfn-thisarg---channel)
|
||||||
- [push(value) -> async bufferLength](#pushvalue---async-bufferlength)
|
- [push(value) -> async bufferLength](#pushvalue---async-bufferlength)
|
||||||
- [reduce(callbackfn[, initialValue])](#reducecallbackfn-initialvalue)
|
- [reduce(callbackfn[, initialValue])](#reducecallbackfn-initialvalue)
|
||||||
|
@ -232,6 +233,10 @@ The values of the channel are converted to Strings, and these Strings are then
|
||||||
concatenated, separated by occurrences of the separator. If no separator is
|
concatenated, separated by occurrences of the separator. If no separator is
|
||||||
provided, a single comma is used as the separator.
|
provided, a single comma is used as the separator.
|
||||||
|
|
||||||
|
### length
|
||||||
|
|
||||||
|
The length of the channel's buffer.
|
||||||
|
|
||||||
### map(callbackfn[, thisArg]) -> Channel
|
### map(callbackfn[, thisArg]) -> Channel
|
||||||
|
|
||||||
`callbackfn` should be a function that accepts one argument. `map` calls
|
`callbackfn` should be a function that accepts one argument. `map` calls
|
||||||
|
|
|
@ -254,7 +254,11 @@ const Channel = function(bufferLength = 0) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperty(readOnly, `value`, { get: () => lastValue });
|
Object.defineProperties(readOnly, {
|
||||||
|
length: { get: () => bufferLength },
|
||||||
|
value: { get: () => lastValue }
|
||||||
|
});
|
||||||
|
|
||||||
Object.freeze(readOnly);
|
Object.freeze(readOnly);
|
||||||
|
|
||||||
const writeOnly = Object.freeze({
|
const writeOnly = Object.freeze({
|
||||||
|
|
|
@ -217,6 +217,10 @@ describe(`Channel object`, function() {
|
||||||
assert.equal(await Channel.of(`a`, `b`, `c`).join(), `a,b,c`);
|
assert.equal(await Channel.of(`a`, `b`, `c`).join(), `a,b,c`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`length`, function() {
|
||||||
|
assert.equal(Channel(42).length, 42);
|
||||||
|
});
|
||||||
|
|
||||||
it(`map`, async function() {
|
it(`map`, async function() {
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
await Channel.of(`a`, `b`, `c`)
|
await Channel.of(`a`, `b`, `c`)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue