<commit_before><?php
/**
 * @package  Garp\Functional
 * @author   <NAME> <<EMAIL>>
 * @license  https://github.com/grrr-amsterdam/garp-functional/blob/master/LICENSE.md BSD-3-Clause
 */
namespace Garp\Functional;

/**
 * Rename keys in an array.
 *
 * @param  mixed $transformMap
 * @param  mixed $collection
 * @return array
 */
function rename_keys($transformMap, array $collection = null) {
    if (!is_callable($transformMap) && !is_array($transformMap)) {
        throw new \InvalidArgumentException(
            'rename_keys expects argument 1 to be an array or a function'
        );
    }
    $transformer = function ($collection) use ($transformMap) {
        return reduce(
            function ($acc, $cur) use ($transformMap, $collection) {
                $prop = is_callable($transformMap)
                    ? $transformMap($cur)
                    : prop($cur, $transformMap);
                return prop_set(
                    $prop ?: $cur,
                    $collection[$cur],
                    $acc
                );
            },
            [],
            keys($collection)
        );
    };
    return func_num_args() < 2 ? $transformer : $transformer($collection);
}<commit_msg>Use PHP5.3 safe syntax in rename_keys<commit_after><?php
/**
 * @package  Garp\Functional
 * @author   <NAME> <<EMAIL>>
 * @license  https://github.com/grrr-amsterdam/garp-functional/blob/master/LICENSE.md BSD-3-Clause
 */
namespace Garp\Functional;

/**
 * Rename keys in an array.
 *
 * @param  mixed $transformMap
 * @param  mixed $collection
 * @return array
 */
function rename_keys($transformMap, array $collection = null) {
    if (!is_callable($transformMap) && !is_array($transformMap)) {
        throw new \InvalidArgumentException(
            'rename_keys expects argument 1 to be an array or a function'
        );
    }
    $transformer = function ($collection) use ($transformMap) {
        return reduce(
            function ($acc, $cur) use ($transformMap, $collection) {
                $prop = is_callable($transformMap)
                    ? $transformMap($cur)
                    : prop($cur, $transformMap);
                return prop_set(
                    $prop ?: $cur,
                    $collection[$cur],
                    $acc
                );
            },
            array(),
            keys($collection)
        );
    };
    return func_num_args() < 2 ? $transformer : $transformer($collection);
}
{'fraction_non_alphanumeric': 0.12901912901912901, 'fraction_numerical': 0.003256003256003256, 'mean_word_length': 1.9939098660170524, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6525293', 'n_tokens_mistral': 695, 'n_tokens_neox': 671, 'n_words': 158}