In this thread, I wrote this function:
using Base.Iterators
function foo(itr, n, fillvalue)
ntake = ceil(Int, length(itr)/n)
extended_itr = flatten( ( itr, repeated(fillvalue) ) )
take(partition(extended_itr, n), ntake)
end
I noticed that when I collect the iterator returned by foo
, the type inference appears to fail:
julia> collect(foo(1:7, 3, 0))
3-element Array{Array{Any,1},1}:
[1, 2, 3]
[4, 5, 6]
[7, 0, 0]
I would expect the output type to be Vector{Vector{Int}}
rather than Vector{Vector{Any}}
. @mkitti pointed out that length
is an optional part of the iteration interface, but I wouldn’t think that would affect the type inference. Can anyone explain why type inference fails here? Should I open an issue on Github?