<commit_before><?php

declare (strict_types = 1);

namespace Mihaeu\PhpDependencies;

abstract class AbstractCollection implements Collection
{
    /** @var array */
    protected $collection = [];

    /**
     * {@inheritdoc}
     */
    public function each(\Closure $closure)
    {
        foreach ($this->collection as $item) {
            $closure($item);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function mapToArray(\Closure $closure) : array
    {
        return array_map($closure, $this->collection);
    }

    /**
     * {@inheritdoc}
     */
    public function reduce($initial, \Closure $closure)
    {
        return array_reduce($this->collection, $closure, $initial);
    }

    /**
     * {@inheritdoc}
     */
    public function filter(\Closure $closure) : Collection
    {
        $clone = clone $this;
        $clone->collection = array_filter($this->collection, $closure);

        return $clone;
    }

    /**
     * {@inheritdoc}
     */
    public function toArray() : array
    {
        return $this->collection;
    }

    /**
     * {@inheritdoc}
     */
    public function count()
    {
        return count($this->collection);
    }
}<commit_msg>Fix bad indices for filtered collection<commit_after><?php

declare (strict_types = 1);

namespace Mihaeu\PhpDependencies;

abstract class AbstractCollection implements Collection
{
    /** @var array */
    protected $collection = [];

    /**
     * {@inheritdoc}
     */
    public function each(\Closure $closure)
    {
        foreach ($this->collection as $item) {
            $closure($item);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function mapToArray(\Closure $closure) : array
    {
        return array_map($closure, $this->collection);
    }

    /**
     * {@inheritdoc}
     */
    public function reduce($initial, \Closure $closure)
    {
        return array_reduce($this->collection, $closure, $initial);
    }

    /**
     * {@inheritdoc}
     */
    public function filter(\Closure $closure) : Collection
    {
        $clone = clone $this;
        $clone->collection = array_values(array_filter($this->collection, $closure));

        return $clone;
    }

    /**
     * {@inheritdoc}
     */
    public function toArray() : array
    {
        return $this->collection;
    }

    /**
     * {@inheritdoc}
     */
    public function count()
    {
        return count($this->collection);
    }
}
{'fraction_non_alphanumeric': 0.14297385620915032, 'fraction_numerical': 0.0008169934640522876, 'mean_word_length': 2.0536159600997506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2614346', 'n_tokens_mistral': 720, 'n_tokens_neox': 692, 'n_words': 147}