summaryrefslogtreecommitdiff
path: root/build-es/internal/applyEach.js
blob: 1467363b75bf88867824f67eafeb6d55830e9321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict';

import rest from 'lodash-es/rest';

export default function applyEach(eachfn) {
    return rest(function(fns, args) {
        var go = rest(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;
        }
    });
}