obj-chain-core
Version:
fluent chaining for obj with dot-prop access
25 lines (23 loc) • 696 B
JavaScript
// https://www.youtube.com/watch?v=SwSle66O5sU
const OFF = `${~315 >>> 3}@@`
/**
* @param {Function[]} funcs functions to flow left to right
* @return {Function} passes args through the functions, bound to this
*/
function flow(...funcs) {
const length = funcs ? funcs.length : 0
return function flowing(...args) {
let index = 0
// log
// .data({length, index, f: funcs[index], args, funcs})
// .blue('flow')
// .echo()
// eslint-disable-next-line
let result = length ? funcs[index].apply(this, args) : args[0]
while (++index < length) {
// eslint-disable-next-line
result = funcs[index].call(this, result)
}
return result
}
}