Как правильно обернуть матрицу и получить доступ с помощью символов?
S = OhlcSeries{Float64}(100)
lastClose = S[:close, 0]
struct OhlcSeries{T} <: AbstractArray{T,2}
data::Matrix{T}
function OhlcSeries{T}(length::Int) where T
data = Matrix{T}(4, length)
new{T}(data)
end
end
# Base.parent(A::OhlcSeries) = A.data
getindex(s::OhlcSeries,sym::Symbol) = getindex(s,Val{sym})
getindex(s::OhlcSeries,::Type{Val{:close}}) = view(s.data, 4, :)
# @inline function getindex(S::InputOhlcSeries, r::Symbol, col::Int)
# @match r begin
# :open => S.data[1, col]
# :high => S.data[2, col]
# :low => S.data[3, col]
# :close => S.data[4, col]
# _ => throw(ArgumentError("Expected one of :open, :high, :low, :close"))
# end
# end
@inline function setindex!(S::InputOhlcSeries, value, r::Symbol, col::Int)
@match r begin
:open => S.data[1, col] = value
:high => S.data[2, col] = value
:low => S.data[3, col] = value
:close => S.data[4, col] = value
_ => throw(ArgumentError("Expected one of :open, :high, :low, :close"))
end
end
@inline Base.getindex(S::OhlcSeries, i::Int, j::Int) = S.data[i, j]
@inline Base.setindex!(S::OhlcSeries, value, i::Int, j::Int) = S.data[i, j] = value
Base.size(S::OhlcSeries) = size(S.data.data)
Base.eltype(::Type{OhlcSeries{T}}) where {T} = T
Base.IndexStyle(::Type{<:OhlcSeries}) = IndexCartesian()