public static function toArray($value)
    {
        if (!is_array($value) && !$value instanceof Traversable) {
            $name = static::of($value);
            throw new TypeException("Can only cast Traversable and arrays to array, not $name");
        }

        return is_array($value) ? $value : iterator_to_array($value);
    }