diff options
Diffstat (limited to 'lib/internal/applyEach.js')
-rw-r--r-- | lib/internal/applyEach.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/internal/applyEach.js b/lib/internal/applyEach.js new file mode 100644 index 0000000..62eadfd --- /dev/null +++ b/lib/internal/applyEach.js @@ -0,0 +1,20 @@ +import restParam from 'lodash/function/restParam'; + +export default function _applyEach(eachfn) { + return restParam(function(fns, args) { + var go = restParam(function(args) { + var that = this; + var callback = args.pop(); + return eachfn(fns, function (fn, _, cb) { + fn.apply(that, args.concat([cb])); + }, + callback); + }); + if (args.length) { + return go.apply(this, args); + } + else { + return go; + } + }); +} |