From 7ede6becf4947371659aaf9cd58a525bc8f932c5 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Wed, 29 May 2019 15:41:32 +0200 Subject: [PATCH 1/2] Fix iteration over Axis Iterate over elements in the Axis instead of just returning the axis. Is in line with `axes(Ax) = OneTo()` and `length(Ax) = `. Also add `Iterator{Size,Eltype}` traits. No tests are broken (that worked before). --- src/core.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core.jl b/src/core.jl index 324b458..486777a 100644 --- a/src/core.jl +++ b/src/core.jl @@ -81,8 +81,11 @@ Base.length(A::Axis) = length(A.val) (A::Axis{name})(i) where {name} = Axis{name}(i) Base.convert(::Type{Axis{name,T}}, ax::Axis{name,T}) where {name,T} = ax Base.convert(::Type{Axis{name,T}}, ax::Axis{name}) where {name,T} = Axis{name}(convert(T, ax.val)) -Base.iterate(a::Axis) = (a, nothing) -Base.iterate(::Axis, ::Any) = nothing +Base.iterate(A::Axis, i...) = Base.iterate(A.val, i...) + +Base.IteratorSize(::Type{<:Axis}) = HasShape{1}() +Base.IteratorEltype(::Type{<:Axis}) = HasEltype() + Base.iterate(::Type{T}) where {T<:Axis} = (T, nothing) Base.iterate(::Type{T}, ::Any) where {T<:Axis} = nothing From 6a1318d7d0c58253b8afe6b34fb81b40e1177df6 Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Wed, 29 May 2019 16:18:19 +0200 Subject: [PATCH 2/2] Qualify HasEltype --- src/core.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core.jl b/src/core.jl index 486777a..9ffd309 100644 --- a/src/core.jl +++ b/src/core.jl @@ -83,8 +83,8 @@ Base.convert(::Type{Axis{name,T}}, ax::Axis{name,T}) where {name,T} = ax Base.convert(::Type{Axis{name,T}}, ax::Axis{name}) where {name,T} = Axis{name}(convert(T, ax.val)) Base.iterate(A::Axis, i...) = Base.iterate(A.val, i...) -Base.IteratorSize(::Type{<:Axis}) = HasShape{1}() -Base.IteratorEltype(::Type{<:Axis}) = HasEltype() +Base.IteratorSize(::Type{<:Axis}) = Base.HasShape{1}() +Base.IteratorEltype(::Type{<:Axis}) = Base.HasEltype() Base.iterate(::Type{T}) where {T<:Axis} = (T, nothing) Base.iterate(::Type{T}, ::Any) where {T<:Axis} = nothing