Collect() requires length() for iterators?

Hi all,

I’m getting a method error when calling collect on an iterator on 0.6. Is this expected?

julia> type Iterable x::Float64 end
julia> Base.start(x::Iterable) = 0
julia> Base.next(x::Iterable, state) = (0, state+1)
julia> Base.done(x::Iterable, state) = state == 1
julia> collect(Iterable(0))
ERROR: MethodError: no method matching length(::Iterable)
1 Like

Base.iteratorsize(::Type{Iterable}) = Base.SizeUnknown()

https://docs.julialang.org/en/stable/manual/interfaces/#man-interface-iteration-1

It defaults to Base.HasLength(). See https://github.com/JuliaLang/julia/issues/22279 for discussion about that default.

1 Like

thx. This must have changed between 0.4 and 0.6 which is why my old code is failing.