<commit_before>"use strict";

var rsvp = require('rsvp');

var _ = module.exports = {

  // Empty placeholder function
  noop: function() {},

  // Loop through objects and arrays
  // Return something truthy from callback to stop iteration
  each: function(items, cb) {
    if(items && items.length != undefined) {
      for(var i = 0; i < items.length; i++) {
        var cancel = cb(items[i], i);
        if(cancel) return cancel;
      }
    } else {
      var i = 0;
      for(var key in items) {
        if(items.hasOwnProperty(key)) {
          var cancel = cb(items[key], key, i++);
          if(cancel) return cancel;
        }
      }
    }
    return false;
  },

  // Return a copy of the given array
  // with each item replaced according to <cbOrName>
  map: function(items, cbOrName) {
    var out = (!items || items.length != undefined ? [] : {});
    var callback = (typeof cbOrName === 'function');
    _.each(items, function(item, key) {
      out[key] = (callback ? cbOrName(item, key) : item[cbOrName]);
    });
    return out;
  },

  // Call the given function <n> times
  times: function(n, cb) {
    for(var i = 0; i < n; i++) {
      var value = cb(i);
      if(value) return value;
    }
  },

  step: function(from , to, steps, cb) {
    return _.times(steps, function(step) {
      return cb(from + (to - from) * step / steps);
    });
  },

  // Invoke the named method on each item
  // Additional arguments will be passed to the invoked methods
  invoke: function(items, key) {
    var out = [];
    var args = Array.prototype.slice.call(arguments).splice(2);
    _.each(items, function(item) {
      out.push(item[key].apply(item, args));
    });
    return out;
  },

  // Interleave the items of two arrays
  zip: function(items1, items2, cb) {
     var out = [];
    _.each(items1, function(item1, i) {
      var item2 = items2[i];
      if(item2 == undefined) return true;
      out.push([item1, item2]);
      cb && cb(item1, item2);
    });
    return out;<commit_msg>Allow for cancelling iteration in #zip<commit_after>"use strict";

var rsvp = require('rsvp');

var _ = module.exports = {

  // Empty placeholder function
  noop: function() {},

  // Loop through objects and arrays
  // Return something truthy from callback to stop iteration
  each: function(items, cb) {
    if(items && items.length != undefined) {
      for(var i = 0; i < items.length; i++) {
        var cancel = cb(items[i], i);
        if(cancel) return cancel;
      }
    } else {
      var i = 0;
      for(var key in items) {
        if(items.hasOwnProperty(key)) {
          var cancel = cb(items[key], key, i++);
          if(cancel) return cancel;
        }
      }
    }
    return false;
  },

  // Return a copy of the given array
  // with each item replaced according to <cbOrName>
  map: function(items, cbOrName) {
    var out = (!items || items.length != undefined ? [] : {});
    var callback = (typeof cbOrName === 'function');
    _.each(items, function(item, key) {
      out[key] = (callback ? cbOrName(item, key) : item[cbOrName]);
    });
    return out;
  },

  // Call the given function <n> times
  times: function(n, cb) {
    for(var i = 0; i < n; i++) {
      var value = cb(i);
      if(value) return value;
    }
  },

  step: function(from , to, steps, cb) {
    return _.times(steps, function(step) {
      return cb(from + (to - from) * step / steps);
    });
  },

  // Invoke the named method on each item
  // Additional arguments will be passed to the invoked methods
  invoke: function(items, key) {
    var out = [];
    var args = Array.prototype.slice.call(arguments).splice(2);
    _.each(items, function(item) {
      out.push(item[key].apply(item, args));
    });
    return out;
  },

  // Interleave the items of two arrays
  zip: function(items1, items2, cb) {
     var out = [];
    _.each(items1, function(item1, i) {
      var item2 = items2[i];
      if(item2 == undefined) return true;
      out.push([item1, item2]);
      if(cb) return cb(item1, item2);
    });
    return out;
{'fraction_non_alphanumeric': 0.14899925871015568, 'fraction_numerical': 0.007412898443291327, 'mean_word_length': 2.436332767402377, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '281578', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1298, 'n_words': 393}