<commit_before><?php

namespace Qmaker\Iterators;

/**
 * Class GroupingIterator
 *
 * Group the element of the sequence
 */
class GroupingIterator extends LazyIterator implements RelationInterface
{
    /**
     * @var \Iterator
     */
    private $source;

    /**
     * Compute key by value
     * @var callable
     */
    protected $keyExtractor = null;

    /**
     * @var Collections\Lookup
     */
    protected $lookup;

    /**
     * Constructor
     * @param \Iterator $source
     * @param callable $keyExtractor
     */
    public function __construct(\Iterator $source, callable $keyExtractor) {
        $this->source = $source;
        $this->keyExtractor = $keyExtractor;
        $this->lookup = new Collections\Lookup();
    }

    /**
     * @see LazyIterator::build
     */
    public function build() {
        $this->source->rewind();

        while ($this->source->valid()) {
            $current = $this->source->current();
            $key = call_user_func($this->keyExtractor, $current);

            $this->lookup->append($key, $current);
            $this->source->next();
        }

        return $this->lookup;
    }

    /**
     * @see RelationInterface::getRelatedIterators
     */
    public function getRelatedIterators()
    {
        return [ $this->source ];
    }
}<commit_msg>behavior for missing keyExtractor in GroupingIterator<commit_after><?php

namespace Qmaker\Iterators;

/**
 * Class GroupingIterator
 *
 * Group the element of the sequence
 */
class GroupingIterator extends LazyIterator implements RelationInterface
{
    /**
     * @var \Iterator
     */
    private $source;

    /**
     * Compute key by value
     * @var callable
     */
    protected $keyExtractor;

    /**
     * @var Collections\Lookup
     */
    protected $lookup;

    /**
     * Constructor
     * @param \Iterator $source
     * @param callable $keyExtractor
     */
    public function __construct(\Iterator $source, callable $keyExtractor = null) {
        $this->source = $source;
        $this->keyExtractor = $keyExtractor;
        $this->lookup = new Collections\Lookup();
    }

    /**
     * @see LazyIterator::build
     */
    public function build() {
        $this->source->rewind();

        while ($this->source->valid()) {
            $current = $this->source->current();
            if (empty($this->keyExtractor)) {
                $key = $this->source->key();
            } else {
                $key = call_user_func($this->keyExtractor, $current, $this->source);
            }

            $this->lookup->append($key, $current);
            $this->source->next();
        }

        return $this->lookup;
    }

    /**
     * @see RelationInterface::getRelatedIterators
     */
    public function getRelatedIterators()
    {
        return [ $this->source ];
    }
}
{'fraction_non_alphanumeric': 0.1384070796460177, 'fraction_numerical': 0.0, 'mean_word_length': 2.0617551462621884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '4995272', 'n_tokens_mistral': 813, 'n_tokens_neox': 788, 'n_words': 169}