<commit_before><?php

/**
 * Created by PhpStorm.
 * User: rgladson
 * Date: 4/8/2016
 * Time: 10:44 AM
 */
namespace PHPixme;

  /**
   * Class __Private__
   * Used for function instances
   *
   */
/**
 * Class __PRIVATE__
 * Place globals here.
 * @internal
 * @package PHPixme
 * @codeCoverageIgnore
 */
class __PRIVATE__
{
  /**
   * @var array Closure instances can be safely placed inside the array
   */
  static $instance = [];
  static $placeholder;

  /**
   * Asserts that the input can be used in some way by user_call_function_array
   * @param $callable
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x->x
   */
  static function assertCallable($callable)
  {
    if (!is_callable($callable)) {
      throw new \InvalidArgumentException('callback must be a callable function');
    }
    return $callable;
  }

  /**
   * Asserts the value is a number
   * @param $number
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x -> x
   */
  static function assertPositiveOrZero($number)
  {
    if (!is_integer($number) || $number < 0) {
      throw new \InvalidArgumentException('argument must be a integer 0 or greater');
    }
    return $number;
  }

  /**
   * Asserts that the input is Traversable
   * @param $arrayLike
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x -> x
   */
  static function assertTraversable($arrayLike)
  {
    if (!is_array($arrayLike) && !($arrayLike instanceof \Traversable)) {
      throw new \InvalidArgumentException('argument must be a Traversable or array');
    }
    return $arrayLike;
  }

  /**
   * Handles the actual currying behavior for the given function
   * @param $prevArgs
   * @param $arity
   * @param $callable
   * @return \Closure
   */
  static function curryGiven($prevArgs, $arity, $callable)
  {
    return function (...$newArgs) use ($arity, $callable, $prevArgs) {
      $args = array_merge($prevArgs, $newArgs);
      if (count($args) >= $arity) {
        return call_user_func_array($callable, $args);
      }
      return self::curryGiven($args, $arity, $callable);
    };
  }

  /**
   * Starts off the currying process for a giveni function
   * @param int $arity
   * @param callable $callable
   * @return \Closure
   * @throws \InvalidArgumentException when $callable is not a callabe
   */
  static function curry($arity = 0, callable $callable)
  {
    self::assertPositiveOrZero($arity);
    self::assertCallable($callable);

    return self::curryGiven([], $arity, $callable);
  }
}

__PRIVATE__::$placeholder = new \stdClass();<commit_msg>- saving work for the weekend.<commit_after><?php

/**
 * Created by PhpStorm.
 * User: rgladson
 * Date: 4/8/2016
 * Time: 10:44 AM
 */
namespace PHPixme;

  /**
   * Class __Private__
   * Used for function instances
   *
   */
/**
 * Class __PRIVATE__
 * Place globals here.
 * @internal
 * @package PHPixme
 * @codeCoverageIgnore
 */
class __PRIVATE__
{
  /**
   * @var array Closure instances can be safely placed inside the array
   */
  static $instance = [];
  static $placeholder;

  /**
   * Asserts that the input can be used in some way by user_call_function_array
   * @param $callable
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x->x
   */
  static function assertCallable($callable)
  {
    if (!is_callable($callable)) {
      throw new \InvalidArgumentException('callback must be a callable function');
    }
    return $callable;
  }

  /**
   * Asserts the value is a number
   * @param $number
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x -> x
   */
  static function assertPositiveOrZero($number)
  {
    if (!is_integer($number) || $number < 0) {
      throw new \InvalidArgumentException('argument must be a integer 0 or greater');
    }
    return $number;
  }

  /**
   * Asserts that the input is Traversable
   * @param $arrayLike
   * @return mixed
   * @throws \InvalidArgumentException
   * @sig x -> x
   */
  static function assertTraversable($arrayLike)
  {
    if (!is_array($arrayLike) && !($arrayLike instanceof \Traversable)) {
      throw new \InvalidArgumentException('argument must be a Traversable or array');
    }
    return $arrayLike;
  }

  /**
   * Handles the actual currying behavior for the given function
   * @param $prevArgs
   * @param $arity
   * @param $callable
   * @param $firstPlaceholder int
   * @return \Closure (...args) -> \Closure|$callable()
   */
  static function curryGiven($prevArgs, $arity, $callable, $firstPlaceholder = -1)
  {
    return function () use ($arity, $callable, $prevArgs, $firstPlaceholder) {
      $left = $arity;
      $prevArgsLength = count($prevArgs);

      $newArgs = func_get_args();
      $newArgsLength = count($newArgs);

      // Kickstart the process from the last known placeholder location
      $outputArgs = $firstPlaceholder < 0 ? $prevArgs : array_slice($prevArgs, 0, $firstPlaceholder);
      // note the new placeholder's possible location
      $nextFirstPlaceholder = -1;
      for (
        $outputIdx = count($outputArgs), $newArgIdx = 0;
        $outputIdx < $prevArgsLength || $newArgIdx < $newArgsLength;
        $outputIdx += 1
      ) {
        if (
          $outputIdx < $prevArgsLength
          && ($prevArgs[$outputIdx] !== static::$placeholder || $outputIdx >= $newArgsLength)
        ) {
          $cell = $prevArgs[$outputIdx];
        } else {
          $cell = $newArgIdx[$newArgIdx];
          $newArgIdx += 1;

        }
        $outputArgs[$outputIdx] = $cell;
        if ($cell !== static::$placeholder) {
          $left -= 1;
        } else if ($nextFirstPlaceholder < 0) {
          // Note the location of the first placeholder for next time.
          $nextFirstPlaceholder = $outputIdx;
        }
      }
      return ($left < 1
        ? call_user_func_array($callable, $outputArgs)
        : self::curryGiven($outputArgs, $arity, $callable, $nextFirstPlaceholder)
      );
    };
  }

  /**
   * Starts off the currying process for a giveni function
   * @param int $arity
   * @param callable $callable
   * @return \Closure
   * @throws \InvalidArgumentException when $callable is not a callable
   */
  static function curry($arity = 0, callable $callable)
  {
    self::assertPositiveOrZero($arity);
    self::assertCallable($callable);

    return self::curryGiven([], $arity, $callable);
  }
}

__PRIVATE__::$placeholder = new \stdClass();
{'fraction_non_alphanumeric': 0.1253503581438804, 'fraction_numerical': 0.005605730302086578, 'mean_word_length': 2.855342136854742, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, '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': '2823106', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1951, 'n_words': 547}