<commit_before>require.paths.unshift("../lib");

var SERVER_PORT = 9080;
var PROXY_PORT = SERVER_PORT + 1;

var assert = require("assert");
var http = require("http");
var fishback = require("fishback");

fishback.setVerbose(false);

/**
 * Asynchronous map function.  For each element of arr, fn(element, callback) is
 * called, where callback receives the result.
 *
 * Example:
 * 
 *   function aadd(i, callback) {
 *       callback(i + 1);
 *   }
 *
 *   amap([ 2, 3, 4 ], aadd, console.log);
 *   // -> [ 3, 4, 5 ]
 *
 * @param arr the array over which 
 * @param fn function of the form function(n, callback)
 * @param callback function of the form function(arr)
 */

function amap(arr, fn, callback) {

    // https://gist.github.com/846521

    if (arr.length == 0) {
        callback([]);
    } else {
        fn(arr[0], function(v) {
            amap(arr.slice(1), fn, function (list) {
                callback([v].concat(list));
            })
        });
    }

}

/**
 * Passed array of async functions (i.e. whose last argument is a callback), and calls
 * them in order.
 *
 * Example:
 *
 *   step([
 *       function (i, callback) {
 *           console.log("got ", i);
 *           callback(null, 7);
 *       },
 *       function (i, callback) {
 *           console.log("got ", i);
 *           callback();
 *       }
 *   ], null, 6);
 *   // -> got 6
 *   // -> got 7
 *
 * @param tasks array of functions with arguments ([arg]..., callback); callback has arguments (err, arg...)
 * @param [optional] errback called if any of the tasks returns an error
 * @param [optional] arg... arguments to the first task
 */

function step(tasks, errback) {
    
    if (tasks && tasks[0]) {
        var args = Array.prototype.slice.call(arguments, 2);
        tasks[0].apply(null, args.concat(function() {
            var args = Array.prototype.slice.call(arguments);
            if (args[0] && errback) {
                errback(args[0]); // error returned, abort tasks
            } else {
                step.apply(null, [tasks.slice(1)].concat(errback, args.slice(1)));<commit_msg>Improve comments.<commit_after>require.paths.unshift("../lib");

var SERVER_PORT = 9080;
var PROXY_PORT = SERVER_PORT + 1;

var assert = require("assert");
var http = require("http");
var fishback = require("fishback");

fishback.setVerbose(false);

/**
 * Asynchronous map function.  For each element of arr, fn(element, callback) is
 * called, where callback receives the result.
 *
 * Example:
 * 
 *   function aadd(i, callback) {
 *       callback(i + 1);
 *   }
 *
 *   amap([ 2, 3, 4 ], aadd, console.log);
 *   // -> [ 3, 4, 5 ]
 *
 * @param arr the array over which 
 * @param fn function of the form function(n, callback)
 * @param callback function of the form function(arr)
 */

function amap(arr, fn, callback) {

    // https://gist.github.com/846521

    if (arr.length == 0) {
        callback([]);
    } else {
        fn(arr[0], function(v) {
            amap(arr.slice(1), fn, function (list) {
                callback([v].concat(list));
            })
        });
    }

}

/**
 * Passed array of async functions (i.e. whose last argument is a callback), and calls
 * them in order.
 *
 * Example:
 *
 *   step([
 *       function (i, callback) {
 *           console.log("got ", i);
 *           callback(null, 7);
 *       },
 *       function (i, callback) {
 *           console.log("got ", i);
 *           callback();
 *       }
 *   ], null, 6);
 *   // -> got 6
 *   // -> got 7
 *
 * @param tasks array of functions with arguments ([arg]..., callback); callback has arguments (err, arg...)
 * @param [optional] errback called if any of the tasks returns an error
 * @param [optional] arg... arguments to the first task
 */

function step(tasks, errback) {
    
    if (tasks && tasks[0]) {
        var args = Array.prototype.slice.call(arguments, 2);
        tasks[0].apply(null, args.concat(function() { // Note: exception thrown if tasks[0] not a function
            var args = Array.prototype.slice.call(arguments);
            if (args[0] && errback) {
                errback(args[0]); // error returned, abort tasks (Note: exception thrown if errback not a function)
            } else {
                step.apply(null, [tasks.slice(1)].concat(errback, args.slice(1)));
{'fraction_non_alphanumeric': 0.15768694844403158, 'fraction_numerical': 0.015095215977705528, 'mean_word_length': 2.287786259541985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '559366', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1325, 'n_words': 390}