Add functional API.

This commit is contained in:
David Braun 2017-10-11 03:32:47 -04:00
parent be51e95eb3
commit 8da51305eb
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF
3 changed files with 91 additions and 2 deletions

View file

@ -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)