Skip to content

Commit 7ede6be

Browse files
committed
Fix iteration over Axis
Iterate over elements in the Axis instead of just returning the axis. Is in line with `axes(Ax) = OneTo(<length of elems>)` and `length(Ax) = <length of elems>`. Also add `Iterator{Size,Eltype}` traits. No tests are broken (that worked before).
1 parent 48ec735 commit 7ede6be

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/core.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ Base.length(A::Axis) = length(A.val)
8181
(A::Axis{name})(i) where {name} = Axis{name}(i)
8282
Base.convert(::Type{Axis{name,T}}, ax::Axis{name,T}) where {name,T} = ax
8383
Base.convert(::Type{Axis{name,T}}, ax::Axis{name}) where {name,T} = Axis{name}(convert(T, ax.val))
84-
Base.iterate(a::Axis) = (a, nothing)
85-
Base.iterate(::Axis, ::Any) = nothing
84+
Base.iterate(A::Axis, i...) = Base.iterate(A.val, i...)
85+
86+
Base.IteratorSize(::Type{<:Axis}) = HasShape{1}()
87+
Base.IteratorEltype(::Type{<:Axis}) = HasEltype()
88+
8689
Base.iterate(::Type{T}) where {T<:Axis} = (T, nothing)
8790
Base.iterate(::Type{T}, ::Any) where {T<:Axis} = nothing
8891

0 commit comments

Comments
 (0)