# Maintaining iterator protocol for both 0.6 and 0.7

**URL:** <https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084>\
**Category:** General Usage\
**Created:** [June 30, 2018, 6:09pm UTC](https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084 "2018-06-30T18:09:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [June 30, 2018, 6:09pm UTC](https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084/1 "2018-06-30T18:09:37Z")

</div>

What’s the best way to make the code work under both 0.6 and 0.7 given the new iterator protocol? Should I just wrap the code around with something like `if VERSION < "0.7"`?

I used to have this:

```julia
Base.start(d::CIDict) = start(d.dct)
Base.next(d::CIDict, i::Int) = next(d.dct, i)
Base.done(d::CIDict, i::Int) = done(d.dct, i)

```

and the new protocol seems to require this:

```julia
Base.iterate(d::CIDict) = iterate(d.dct)
Base.iterate(d::CIDict, i) = iterate(d.dct, i)

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [June 30, 2018, 6:14pm UTC](https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084/2 "2018-06-30T18:14:29Z")

</div>

Just use the old protocol for as long as you want 0.6 compatibility. It still works in 0.7, or so I thought?

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [June 30, 2018, 6:20pm UTC](https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084/3 "2018-06-30T18:20:11Z")

</div>

It didn’t work and that’s why I started looking into it… Maybe I’m missing something else?

Where it failed:

```julia
for (k,v) in d
    # whatever     
end

```

Stack trace:

```julia
case insensitive dict: Error During Test at /Users/tomkwong/.julia/dev/SASLib/test/runtests.jl:55
  Got exception MethodError(done, (CIDict(:abc => 88, :def => 77), Base.LegacyIterationCompat{Dict{Symbol,Int64},Pair{Symbol,Int64},Int64}(false, :abc => 88, 5)), 0x0000000000006b0d) outside of a @test
  MethodError: no method matching done(::SASLib.CIDict{Symbol,Int64}, ::Base.LegacyIterationCompat{Dict{Symbol,Int64},Pair{Symbol,Int64},Int64})
  Closest candidates are:
    done(::I, !Matched::Base.LegacyIterationCompat{I,T,S}) where {I, T, S} at essentials.jl:870
    done(!Matched::Missings.EachReplaceMissing, ::Any) at /Users/tomkwong/.julia/packages/Missings/Fu1R/src/Missings.jl:304
    done(!Matched::Missings.EachFailMissing, ::Any) at /Users/tomkwong/.julia/packages/Missings/Fu1R/src/Missings.jl:427
    ...
  Stacktrace:
   [1] iterate at ./essentials.jl:827 [inlined]
   [2] iterate at ./essentials.jl:831 [inlined]
   [3] (::getfield(Main, Symbol("#testdict#19")))(::Symbol, ::Symbol, ::Symbol) at /Users/tomkwong/.julia/dev/SASLib/test/runtests.jl:78
   [4] macro expansion at /Users/tomkwong/.julia/dev/SASLib/test/runtests.jl:56 [inlined]
   [5] macro expansion at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/Test/src/Test.jl:1080 [inlined]
   [6] macro expansion at /Users/tomkwong/.julia/dev/SASLib/test/runtests.jl:20 [inlined]
   [7] macro expansion at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v0.7/Test/src/Test.jl:1080 [inlined]
   [8] top-level scope at /Users/tomkwong/.julia/dev/SASLib/test/runtests.jl:19 [inlined]

```

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [June 30, 2018, 7:02pm UTC](https://discourse.julialang.org/t/maintaining-iterator-protocol-for-both-0-6-and-0-7/12084/4 "2018-06-30T19:02:05Z")

</div>

> [@tk3369](#):
>
> What’s the best way to make the code work under both 0.6 and 0.7 given the new iterator protocol? Should I just wrap the code around with something like `if VERSION < "0.7"` ?

Yes, I’d recommend this. You can use femtocleaner to remove the compatibility definitions when you’re ready to drop 0.6.
