Open
Description
Currently when you show an IdOffsetRange
it displays indices
and values
:
julia> a = OffsetArrays.IdOffsetRange(1:4, 4)
OffsetArrays.IdOffsetRange(values=5:8, indices=5:8)
The intuition from this display is that an IdOffsetRange
might have a values
and indices
property. However, this is not the case.
julia> a.values
ERROR: type IdOffsetRange has no field values
Stacktrace:
[1] getproperty(x::OffsetArrays.IdOffsetRange{Int64, UnitRange{Int64}}, f::Symbol)
@ Base ./Base.jl:38
[2] top-level scope
@ REPL[112]:1
julia> a.indices
ERROR: type IdOffsetRange has no field indices
Stacktrace:
[1] getproperty(x::OffsetArrays.IdOffsetRange{Int64, UnitRange{Int64}}, f::Symbol)
@ Base ./Base.jl:38
[2] top-level scope
@ REPL[113]:1
I suggest that we add those properties based on what is shown via show
:
Line 278 in 08dc371
An example implementation is as follows.
julia> Base.getproperty(r::IdOffsetRange, s::Symbol) = hasfield(typeof(r),s) ? getfield(r,s) :
s == :values ? (first(r):last(r)) :
s == :indices ? (first(eachindex(r)) : last(eachindex(r))) :
error("type IdOffsetRange has no property $s")
julia> Base.propertynames(r::IdOffsetRange) = (fieldnames(typeof(r))..., :values, :indices)
julia> a.offset
4
julia> a.parent
1:4
julia> a.indices
5:8
julia> a.values
5:8
Metadata
Metadata
Assignees
Labels
No labels