<commit_before><?php

namespace Emonkak\Collection;

use Emonkak\Collection\Provider\GeneratorProvider;
use Emonkak\Collection\Provider\ICollectionProvider;
use Emonkak\Collection\Provider\IteratorProvider;
use Emonkak\Collection\Util\Iterators;

class Collection implements \IteratorAggregate
{
    use Enumerable;
    use EnumerableAliases;

    private static $defaultProvider;

    private $source;

    private $provider;

    public static function from($source)
    {
        if (!Iterators::isTraversable($source)) {
            throw new \InvalidArgumentException('This source can not be traversable.');
        }

        return new Collection($source, self::$defaultProvider);
    }

    public static function range($start, $stop = null, $step = 1)
    {
        if ($stop === null) {
            $stop = $start;
            $start = 0;
        }
        return new Collection(
            self::$defaultProvider->range($start, $stop, $step),
            self::$defaultProvider
        );
    }

    public static function iterate($initial, $f)
    {
        return new Collection(
            self::$defaultProvider->iterate($initial, $f),
            self::$defaultProvider
        );
    }

    public static function repeat($value, $n = null)
    {
        return new Collection(
            self::$defaultProvider->repeat($value, $n),
            self::$defaultProvider
        );
    }

    public static function setDefaultProvider(ICollectionProvider $provider)
    {
        self::$defaultProvider = $provider;
    }

    public static function getDefaultProvider()
    {
        return self::$defaultProvider;
    }

    public function __construct($source, ICollectionProvider $provider)
    {
        $this->source = $source;
        $this->provider = $provider;
    }

    public function getSource()
    {
        return $this->source;
    }

    public function getProvider()
    {
        return $this->provider;
    }

    public function getIterator()
    {
        return Iterators::create($this->source);
    }
}

if (class_exists('Generator')) {
    Collection::setDefaultProvider(GeneratorProvider::getInstance());
} else {
    Collection::setDefaultProvider(IteratorProvider::getInstance());
}
<commit_msg>Improve exception message on Collection::from()<commit_after><?php

namespace Emonkak\Collection;

use Emonkak\Collection\Provider\GeneratorProvider;
use Emonkak\Collection\Provider\ICollectionProvider;
use Emonkak\Collection\Provider\IteratorProvider;
use Emonkak\Collection\Util\Iterators;

class Collection implements \IteratorAggregate
{
    use Enumerable;
    use EnumerableAliases;

    private static $defaultProvider;

    private $source;

    private $provider;

    public static function from($source)
    {
        if (!Iterators::isTraversable($source)) {
            $type = gettype($source);
            throw new \InvalidArgumentException("'$type' can not be traversable.");
        }

        return new Collection($source, self::$defaultProvider);
    }

    public static function range($start, $stop = null, $step = 1)
    {
        if ($stop === null) {
            $stop = $start;
            $start = 0;
        }
        return new Collection(
            self::$defaultProvider->range($start, $stop, $step),
            self::$defaultProvider
        );
    }

    public static function iterate($initial, $f)
    {
        return new Collection(
            self::$defaultProvider->iterate($initial, $f),
            self::$defaultProvider
        );
    }

    public static function repeat($value, $n = null)
    {
        return new Collection(
            self::$defaultProvider->repeat($value, $n),
            self::$defaultProvider
        );
    }

    public static function setDefaultProvider(ICollectionProvider $provider)
    {
        self::$defaultProvider = $provider;
    }

    public static function getDefaultProvider()
    {
        return self::$defaultProvider;
    }

    public function __construct($source, ICollectionProvider $provider)
    {
        $this->source = $source;
        $this->provider = $provider;
    }

    public function getSource()
    {
        return $this->source;
    }

    public function getProvider()
    {
        return $this->provider;
    }

    public function getIterator()
    {
        return Iterators::create($this->source);
    }
}

if (class_exists('Generator')) {
    Collection::setDefaultProvider(GeneratorProvider::getInstance());
} else {
    Collection::setDefaultProvider(IteratorProvider::getInstance());
}

{'fraction_non_alphanumeric': 0.11362637362637362, 'fraction_numerical': 0.0008791208791208791, 'mean_word_length': 2.643714971977582, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '188516', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1190, 'n_words': 267}