<commit_before><?php
namespace TRex\Collection;

trait CollectionFilterTrait
{
    /**
     * @param callable|null $filter
     * @param int $flag (only for php version >= 5.6)
     * @return $this
     */
    public function filter(callable $filter = null, $flag = 0)
    {
        if (version_compare(phpversion(), '5.6.0', '>=')) {
            return new $this(array_filter((array)$this, $filter, $flag));
        }
        return new $this(array_filter((array)$this, $filter));
    }

    /**
     * Executes the callback for every value.
     * Returns a collection with the result of each callback call.
     *
     * @param callable $callback
     * @param array $args
     * @return $this
     */
    public function each(callable $callback, array $args = [])
    {
        return new $this(array_map(
            function($value) use($callback, $args){
                return call_user_func($callback, $value, $args) ?: $value;
            },
            (array)$this
        ));
    }

    /**
     * Extracts the sequence of elements.
     * Starts at index $startIndex and stop after $length keys.
     *
     * @param int $startIndex
     * @param int $length
     * @param bool $areKeysPreserved
     * @return mixed
     */
    public function extract($startIndex, $length = 0, $areKeysPreserved = true)
    {
        $collection = (array) $this;
        $length = $length ?: count($collection);
        return new $this(array_slice($collection, $startIndex, $length, $areKeysPreserved));
    }
}<commit_msg>fix array_filter behavior according to hhvm<commit_after><?php
namespace TRex\Collection;

trait CollectionFilterTrait
{
    /**
     * @param callable|null $filter
     * @param int $flag (only for php version >= 5.6)
     * @return $this
     */
    public function filter(callable $filter = null, $flag = 0)
    {
        if (defined('HHVM_VERSION')) {
            if (version_compare(HHVM_VERSION, '3.8.1', '>=')) {
                return new $this(array_filter((array)$this, $filter, $flag));
            }
        } else {
            if (version_compare(phpversion(), '5.6.0', '>=')) {
                return new $this(array_filter((array)$this, $filter, $flag));
            }
        }
        return new $this(array_filter((array)$this, $filter));
    }

    /**
     * Executes the callback for every value.
     * Returns a collection with the result of each callback call.
     *
     * @param callable $callback
     * @param array $args
     * @return $this
     */
    public function each(callable $callback, array $args = [])
    {
        return new $this(array_map(
            function ($value) use ($callback, $args) {
                return call_user_func($callback, $value, $args) ?: $value;
            },
            (array)$this
        ));
    }

    /**
     * Extracts the sequence of elements.
     * Starts at index $startIndex and stop after $length keys.
     *
     * @param int $startIndex
     * @param int $length
     * @param bool $areKeysPreserved
     * @return mixed
     */
    public function extract($startIndex, $length = 0, $areKeysPreserved = true)
    {
        $collection = (array)$this;
        $length = $length ?: count($collection);
        return new $this(array_slice($collection, $startIndex, $length, $areKeysPreserved));
    }
}
{'fraction_non_alphanumeric': 0.133756038647343, 'fraction_numerical': 0.005132850241545894, 'mean_word_length': 2.2608267716535435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '6318737', 'n_tokens_mistral': 987, 'n_tokens_neox': 971, 'n_words': 263}