JuliaParallel / JuliaParallel/Dagger.jl
`iterate` for `Thunk`s
- Dominant language
- Julia
- Stars
- 723
- Forks
- 90
- Avg merge
- 1d 37m
- Merged PRs (30d)
- 9
Description
Currently if you try to unpack a result from `delayed` into several bindings on the lhs
```julia-repl
julia> using Dagger
julia> swap(a, b) = b, a
swap (generic function with 1 method)
julia> x, y = delayed(swap)(1, 2)
MethodError: no method matching iterate(::Thunk)
Closest candidates are:
iterate(::Union{LinRange, StepRangeLen}) at range.jl:664
iterate(::Union{LinRange, StepRangeLen}, ::Int64) at range.jl:664
iterate(::T) where T<:Union{Base.KeySet{var"#s79", var"#s78"} where {var"#s79", var"#s78"<:Dict}, Base.ValueIterator{var"#s77"} where var"#s77"<:Dict} at dict.jl:693
...
```
you end up with a method error since `delayed` just returns a single `Thunk`.
Would it make sense to add an `iterate` method for `Thunk` such that you can decompose these calls correctly? From a brief test the following appears to work alright.
```julia-repl
julia> Base.iterate(t::Thunk, index::Integer=1) = delayed(first ∘ iterate)(t, index), index + 1
julia> x, y = delayed(swap)(1, 2)
Thunk(swap, (1, 2))
julia> collect.((x, y))
(2, 1)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.