JuliaFolds2 / ChunkSplitters.jl

Simple chunk splitters for parallel loop executions
MIT License
40 stars 5 forks source link

Support `eachindex` for `ChunkSplitters.Enumerate` #41

Closed carstenbauer closed 1 day ago

carstenbauer commented 2 days ago

I want this to work:

eachindex(enumerate(chunks(rand(10); n=5)))

Deeper reason is that we use eachindex in OhMyThreads.jl and the above is required for the following to work:

@tasks for (c, v) in enumerate(chunks(rand(10); n=5))
    # ...
end

As a simple solution, we could define

Base.keys(x::ChunkSplitters.Enumerate) = Base.OneTo(x.itr.n)

or, alternatively, Base.eachindex directly.

lmiq commented 2 days ago

I would go for eachindex, but any option is fine.

lmiq commented 2 days ago

I think this is better, because it works with chunks(rand(10); size=2) as well:

eachindex(ec::Enumerate{<:Chunk}) = Base.OneTo(length(ec.itr))

PR: https://github.com/JuliaFolds2/ChunkSplitters.jl/pull/42

lmiq commented 1 day ago

Released in 2.5.0 just now.