<commit_before>var Promise = require('promise');


function identity(x) {
    return x;
}

function argsOrArr(func) {
    return function(arr) {
        if (arguments.length > 1) {
            arr = Array.prototype.slice.call(arguments, 0);
        } else if (!(arr instanceof Array)) {
            arr = [arr];
        }
        return func.call(this, arr);
    };
}


exports.getResolved = function(val) {
    return new Promise(function(res) {
        res(val);
    });
};
exports.getRejected = function(val) {
    return new Promise(function(_, rej) {
        rej(val);
    });
};


exports.all = Promise.all.bind(Promise);

exports.first = argsOrArr(function(arr) {
    return new Promise(function(resolve, reject) {
        for (var i = 0; i < arr.length; i++) {
            arr[i].then(resolve, reject);
        }
    });
});

exports.any = argsOrArr(function(arr) {
    var len = arr.length;
    var rejected = 0;
    return new Promise(function(resolve, reject) {
        for (var i = 0; i < len; i++) {
            arr[i].then(resolve, function() {
                rejected++;
                if (rejected === len) {
                    reject();
                }<commit_msg>Alias first() to race()<commit_after>var Promise = require('promise');


function identity(x) {
    return x;
}

function argsOrArr(func) {
    return function(arr) {
        if (arguments.length > 1) {
            arr = Array.prototype.slice.call(arguments, 0);
        } else if (!(arr instanceof Array)) {
            arr = [arr];
        }
        return func.call(this, arr);
    };
}


exports.getResolved = function(val) {
    return new Promise(function(res) {
        res(val);
    });
};
exports.getRejected = function(val) {
    return new Promise(function(_, rej) {
        rej(val);
    });
};


exports.all = Promise.all.bind(Promise);

exports.first = exports.race = argsOrArr(function(arr) {
    return new Promise(function(resolve, reject) {
        for (var i = 0; i < arr.length; i++) {
            arr[i].then(resolve, reject);
        }
    });
});

exports.any = argsOrArr(function(arr) {
    var len = arr.length;
    var rejected = 0;
    return new Promise(function(resolve, reject) {
        for (var i = 0; i < len; i++) {
            arr[i].then(resolve, function() {
                rejected++;
                if (rejected === len) {
                    reject();
                }
{'fraction_non_alphanumeric': 0.14935335836462243, 'fraction_numerical': 0.004171881518564873, 'mean_word_length': 2.0547770700636945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3149609', 'n_tokens_mistral': 755, 'n_tokens_neox': 728, 'n_words': 170}