<commit_before>/*!
 * iterator-promise <https://github.com/doowb/iterator-promise>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

/**
 * Iterate over a stack of promise functions passing the results of
 * each function to the next function in the stack.
 *
 * @param  {Array} `stack` Array of functions to call.
 * @return {Function} Returns a function that will iterator over the given stack of functions.
 * @api public
 * @name  iterator
 */

module.exports = function iteratorPromise (stack) {
  return function (/* arguments */) {
    var Promise = require('bluebird');
    var self = this;
    var args = [].slice.call(arguments);
    var current = Promise.method(function (arg) {
      return arg;
    });

    if (!stack.length) {
      return current(args[0]);
    }
    var first = stack.shift();
    if (!stack.length) {
      return first.apply(self, args);
    }
    return Promise.reduce(stack, function (acc, fn) {
      return fn(acc);
    }, first.apply(self, args));
  };
};<commit_msg>minor edits, ensure context is correct<commit_after>/*!
 * iterator-promise <https://github.com/doowb/iterator-promise>
 *
 * Copyright (c) 2015, <NAME>.
 * Licensed under the MIT License.
 */

'use strict';

/**
 * Iterate over a stack of promise functions passing the results of
 * each function to the next function in the stack.
 *
 * @param  {Array} `stack` Array of functions to call.
 * @return {Function} Returns a function that will iterator over the given stack of functions.
 * @api public
 * @name  iterator
 */

module.exports = function iteratorPromise (stack) {
  var self = this;

  return function () {
    var args = [].slice.call(arguments);
    var Promise = require('bluebird');
    var current = Promise.method(function (arg) {
      return arg;
    });

    if (!stack.length) {
      return current(args[0]);
    }

    var first = stack.shift();
    if (!stack.length) {
      return first.apply(self, args);
    }

    return Promise.reduce(stack, function (acc, fn) {
      return fn(acc);
    }, first.apply(self, args));
  };
};
{'fraction_non_alphanumeric': 0.1355206847360913, 'fraction_numerical': 0.004755111745126011, 'mean_word_length': 3.0383877159309023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7495502', 'n_tokens_mistral': 634, 'n_tokens_neox': 619, 'n_words': 210}