<commit_before><?php
/**
 * PHP Package: axelitus/base - Primitive operations and helpers.
 *
 * @author      <NAME> (<EMAIL>)
 * @copyright   2013 - <NAME>
 * @link        http://axelitus.mx/projects/axelitus/base
 * @license     MIT License ({@link LICENSE.md})
 * @package     axelitus\Base
 * @version     0.7.2
 */

namespace axelitus\Base;

/**
 * Class Traverser
 *
 * Array traverser.
 *
 * @package axelitus\Base
 */
class Traverser
{
    /**
     * Runs the traverser across the given array and executes the item callback into every item of the array.
     *
     * The traverser also has a result callback to allow for 'macro' result processing.
     *
     * @param array    $arr The array to traverse.
     * @param callable $itemCallback The item callback to operate into every item.
     * @param callable $resultCallback The result callback to operate into the result array.
     *
     * @return array
     */
    public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
    {
        $result = [];
        foreach ($arr as $key => &$value) {
            // Run the callback and store the result in a variable so that we allow the key to be modified by the callback.
            // also pass the original array if one needs to unset variables from the original array.
            $r = $itemCallback($value, $key, $arr);

            // Store the item callback's result with the (new) key.
            $result[$key] = $r;
        }

        if (!is_null($resultCallback)) {
            // Allow for the original array to be modified with the result array.
            return $resultCallback($result, $arr);
        }

        return $result;
    }
}
<commit_msg>Formatted code.<commit_after><?php
/**
 * PHP Package: axelitus/base - Primitive operations and helpers.
 *
 * @author      <NAME> (<EMAIL>)
 * @copyright   2013 - <NAME>
 * @link        http://axelitus.mx/projects/axelitus/base
 * @license     MIT License ({@link LICENSE.md})
 * @package     axelitus\Base
 * @version     0.7.2
 */

namespace axelitus\Base;

/**
 * Class Traverser
 *
 * Array traverser.
 *
 * @package axelitus\Base
 */
class Traverser
{
    /**
     * Runs the traverser across the given array and executes the item callback into every item of the array.
     *
     * The traverser also has a result callback to allow for 'macro' result processing.
     *
     * @param array    $arr            The array to traverse.
     * @param callable $itemCallback   The item callback to operate into every item.
     * @param callable $resultCallback The result callback to operate into the result array.
     *
     * @return array
     */
    public static function run(array &$arr, callable $itemCallback, callable $resultCallback = null)
    {
        $result = [];
        foreach ($arr as $key => &$value) {
            // Run the callback and store the result in a variable so that we allow the key to be modified by the
            // callback. Also pass the original array if one needs to unset variables from the original array.
            $r = $itemCallback($value, $key, $arr);

            // Store the item callback's result with the (new) key.
            $result[$key] = $r;
        }

        if (!is_null($resultCallback)) {
            // Allow for the original array to be modified with the result array.
            return $resultCallback($result, $arr);
        }

        return $result;
    }
}

{'fraction_non_alphanumeric': 0.10113010721529991, 'fraction_numerical': 0.004056795131845842, 'mean_word_length': 2.268939393939394, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3690381', 'n_tokens_mistral': 983, 'n_tokens_neox': 936, 'n_words': 371}