Add functional API.
This commit is contained in:
parent
be51e95eb3
commit
8da51305eb
3 changed files with 91 additions and 2 deletions
24
lib/index.js
24
lib/index.js
|
@ -311,4 +311,28 @@ Channel.select = (...methodPromises) => {
|
|||
return promise
|
||||
}
|
||||
|
||||
// functional interface allowing full or partial application
|
||||
//
|
||||
// Channel.slice(10, Infinity, channel)
|
||||
//
|
||||
// or
|
||||
//
|
||||
// const skipTen = Channel.slice(10, Infinity)
|
||||
// skipTen(channel)
|
||||
|
||||
const channel = Channel()
|
||||
const methods = Object.keys(channel).concat(Object.keys(channel.readOnly()))
|
||||
|
||||
methods.forEach((method) => {
|
||||
Channel[method] = (...args) => {
|
||||
const arity = method === `slice`
|
||||
? 3
|
||||
: channel[method].length
|
||||
|
||||
return args.length >= arity
|
||||
? args[arity - 1][method](...args.slice(0, arity - 1))
|
||||
: (channel) => channel[method](...args)
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = Object.freeze(Channel)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue