<commit_before>// import Methanal.Preds



/**
 * Data validations.
 *
 * Validators are attached to form inputs, and help users input accurate data
 * in realtime. A validator returns an error message, as a C{String}, if the
 * data did not pass validation, otherwise C{undefined} is returned to indicate
 * successful validation.
 */



/**
 * Create a validator from a predicate.
 */
Methanal.Validators.pred = function (p, message) {
    return function (/*...*/) {
        if (!p.apply(null, arguments)) {
            return message;
        }
    };
};



/**
 * Logical AND combiner, with short-circuiting, for validator results.
 */
Methanal.Validators.AND = function AND(values) {
    for (var i = 0; i < values.length; ++i) {
        if (values[i] !== undefined) {
            return values[i];
        }
    }
};



/**
 * Logical intersection of combined validator results.
 *
 * @type  fs: C{Array} of C{Function}s
 * @param fs: Validators whose results should be intersected.
 *
 * @rtype: C{Function} taking varargs.
 * @return: Function that can be called, with varargs, to perform the
 *     intersection.
 */
Methanal.Validators.intersection = Methanal.Util.partial(
    Methanal.Preds.combine, Methanal.Validators.AND);



/**
 * Create a validator that is only executed if C{pred} is C{true}.
 */
Methanal.Validators.ifThen = function ifThen(pred, validator) {
    return function (/*...*/) {
        if (pred.apply(null, arguments)) {
            return validator.apply(null, arguments);
        }<commit_msg>Use special short-circuiting logic for Methanal.Validators.intersection.<commit_after>// import Methanal.Preds



/**
 * Data validations.
 *
 * Validators are attached to form inputs, and help users input accurate data
 * in realtime. A validator returns an error message, as a C{String}, if the
 * data did not pass validation, otherwise C{undefined} is returned to indicate
 * successful validation.
 */



/**
 * Create a validator from a predicate.
 */
Methanal.Validators.pred = function (p, message) {
    return function (/*...*/) {
        if (!p.apply(null, arguments)) {
            return message;
        }
    };
};



/**
 * Logical intersection of combined validator results.
 *
 * @type  fs: C{Array} of C{Function}s
 * @param fs: Validators whose results should be intersected.
 *
 * @rtype: C{Function} taking varargs.
 * @return: Function that can be called, with varargs, to perform the
 *     intersection.
 */
Methanal.Validators.intersection = function intersection(fs) {
    return function _intersect(/*...*/) {
        for (var i = 0; i < fs.length; ++i) {
            var res = fs[i].apply(null, arguments);
            if (res !== undefined) {
                return res;
            }
        }
    };
};



/**
 * Create a validator that is only executed if C{pred} is C{true}.
 */
Methanal.Validators.ifThen = function ifThen(pred, validator) {
    return function (/*...*/) {
        if (pred.apply(null, arguments)) {
            return validator.apply(null, arguments);
        }
{'fraction_non_alphanumeric': 0.12647831800262813, 'fraction_numerical': 0.000657030223390276, 'mean_word_length': 2.690909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6626847', 'n_tokens_mistral': 919, 'n_tokens_neox': 889, 'n_words': 290}