summaryrefslogtreecommitdiff
path: root/lib/internal/applyEach.js
blob: 1d7a0b69740df3048cf4c2a8bc5e7d549983c023 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import rest from 'lodash/_baseRest';
import initialParams from './initialParams';

export default function applyEach(eachfn) {
    return rest(function(fns, args) {
        var go = initialParams(function(args, callback) {
            var that = this;
            return eachfn(fns, function (fn, cb) {
                fn.apply(that, args.concat([cb]));
            }, callback);
        });
        if (args.length) {
            return go.apply(this, args);
        }
        else {
            return go;
        }
    });
}