<commit_before><?php
namespace Eris\Generator;
use Eris\Generator;
use DomainException;

function seq(Generator $singleElementGenerator, $currentSize = 1000)
{
    // TODO: Generator::box($singleElementGenerator);
    if (!($singleElementGenerator instanceof Generator)) {
        $singleElementGenerator = new Constant($singleElementGenerator);
    }
    // TODO: Generator::box($currentSize);
    if (!($sizeGenerator instanceof Generator)) {
        $sizeGenerator = new Constant($sizeGenerator);
    }
    return new Sequence($singleElementGenerator, $currentSize);
}

class Sequence implements Generator
{
    private $singleElementGenerator;
    private $sizeGenerator;

    public function __construct(Generator $singleElementGenerator, Generator $currentSize)
    {
        $this->singleElementGenerator = $singleElementGenerator;
        $this->sizeGenerator = $currentSize;
    }

    public function __invoke()
    {
        return $this->vector($this->sizeGenerator->__invoke())->__invoke();
    }

    public function shrink($sequence)
    {
        if (!$this->contains($sequence)) {
            throw new DomainException(
                'Cannot shrink {' . var_export($sequence, true) . '} because ' .
                'it does not belong to the domain of this sequence'
            );
        }

        $willShrinkInSize = (new Boolean())->__invoke();
        if ($willShrinkInSize) {
            $sequence = $this->shrinkInSize($sequence);
        }
        if (!$willShrinkInSize) {
            $sequence = $this->shrinkTheElements($sequence);
        }
        return $sequence;
    }

    public function contains($sequence)
    {
        return $this->vector(count($sequence))->contains($sequence);
    }

    private function shrinkInSize($sequence)
    {
        $indexOfElementToRemove = array_rand($sequence);<commit_msg>Do not try to shrink empty arrays... :-)<commit_after><?php
namespace Eris\Generator;
use Eris\Generator;
use DomainException;

function seq(Generator $singleElementGenerator, $currentSize = 1000)
{
    // TODO: Generator::box($singleElementGenerator);
    if (!($singleElementGenerator instanceof Generator)) {
        $singleElementGenerator = new Constant($singleElementGenerator);
    }
    // TODO: Generator::box($currentSize);
    if (!($sizeGenerator instanceof Generator)) {
        $sizeGenerator = new Constant($sizeGenerator);
    }
    return new Sequence($singleElementGenerator, $currentSize);
}

class Sequence implements Generator
{
    private $singleElementGenerator;
    private $sizeGenerator;

    public function __construct(Generator $singleElementGenerator, Generator $currentSize)
    {
        $this->singleElementGenerator = $singleElementGenerator;
        $this->sizeGenerator = $currentSize;
    }

    public function __invoke()
    {
        return $this->vector($this->sizeGenerator->__invoke())->__invoke();
    }

    public function shrink($sequence)
    {
        if (!$this->contains($sequence)) {
            throw new DomainException(
                'Cannot shrink {' . var_export($sequence, true) . '} because ' .
                'it does not belong to the domain of this sequence'
            );
        }

        $willShrinkInSize = (new Boolean())->__invoke();
        if ($willShrinkInSize) {
            $sequence = $this->shrinkInSize($sequence);
        }
        if (!$willShrinkInSize) {
            $sequence = $this->shrinkTheElements($sequence);
        }
        return $sequence;
    }

    public function contains($sequence)
    {
        return $this->vector(count($sequence))->contains($sequence);
    }

    private function shrinkInSize($sequence)
    {
        if (count($sequence) === 0) {
            return $sequence;
        }

        $indexOfElementToRemove = array_rand($sequence);
{'fraction_non_alphanumeric': 0.12052631578947369, 'fraction_numerical': 0.002368421052631579, 'mean_word_length': 2.8984615384615386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '7297167', 'n_tokens_mistral': 1016, 'n_tokens_neox': 975, 'n_words': 219}