Closed carstenbauer closed 5 months ago
I definitely prefer returning the empty vector.
To return the empty step range vector one must return nothing
from iterate
. Additionaly, it seems consistent to return nothing
from getchunk
. I have implemented this here:
https://github.com/JuliaFolds2/ChunkSplitters.jl/pull/31/files
One additional thing, which I found slightly inelegant, is that we need to compute the length of the iterator by:
length(c::Chunk{T,FixedSize}) where {T} = cld(length(c.itr), max(1, c.size))
because c.size
can be zero and still be a valid, empty, iterator.
Thus, now, we get:
@test getchunk(10:9, 1; n=2) === nothing
@test getchunk(10:9, 1; size=2) === nothing
@test collect(chunks(10:9; n=2)) == Vector{StepRange{Int,Int}}()
@test collect(chunks(10:9; size=2)) == Vector{StepRange{Int,Int}}()
@test collect(enumerate(chunks(10:9; n=2))) == Tuple{Int64,Vector{StepRange{Int,Int}}}[]
@test collect(enumerate(chunks(10:9; size=2))) == Tuple{Int64,Vector{StepRange{Int,Int}}}[]
If you have any comment, let me know.
fixed in v2.4.2
The error message is clearly wrong and bad.
The fundamental question is what should happen in this case. We could (1) improve the error message or (2) return an empty
Vector{StepRange{Int64, Int64}}
(consistent with the finite case, e.g.collect(chunks(9:10; n=6))
).Came up in https://github.com/JuliaFolds2/OhMyThreads.jl/issues/86.