<commit_before><?php

namespace Funct\Collection;

use Traversable;

/**
 * Returns a copy of the array with all falsy values removed
 *
 * @param array $collection
 *
 * @return array
 * @author <NAME> <<EMAIL>>
 */
function compact($collection)
{
    return array_filter($collection);
}


/**
 * Sorts a array into groups and returns a count for the number of objects in each group. Similar to groupBy, but
 * instead of returning a array of values, returns a count for the number of values in that group.
 *
 * @param array           $collection
 * @param callable|string $callback
 *
 * @return array
 * @author <NAME> <<EMAIL>>
 */
function countBy($collection, $callback)
{
    $result = [];

    foreach ($collection as $key => $value) {<commit_msg>feature for counting elements in a collection<commit_after><?php

namespace Funct\Collection;

use Traversable;

/**
 * Returns a copy of the array with all falsy values removed
 *
 * @param array $collection
 *
 * @return array
 * @author <NAME> <<EMAIL>>
 */
function compact($collection)
{
    return array_filter($collection);
}

/**
 * Count all elements in a collection
 * @param  array  $collection     collection
 * @param  boolean $countRecursive count or not to count recursively
 * @return int                  number of elements in a collection
 * @author <NAME> <<EMAIL>>
 */
function count($collection, $countRecursive = false)
{
    return \count($collection, $countRecursive);
}

/**
 * Sorts a array into groups and returns a count for the number of objects in each group. Similar to groupBy, but
 * instead of returning a array of values, returns a count for the number of values in that group.
 *
 * @param array           $collection
 * @param callable|string $callback
 *
 * @return array
 * @author <NAME> <<EMAIL>>
 */
function countBy($collection, $callback)
{
    $result = [];

    foreach ($collection as $key => $value) {
{'fraction_non_alphanumeric': 0.11076115485564304, 'fraction_numerical': 0.0, 'mean_word_length': 3.5927710843373495, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '4695491', 'n_tokens_mistral': 532, 'n_tokens_neox': 529, 'n_words': 217}