# Can I get a code review on this wrapper class inheriting from AbstractArray

**URL:** <https://discourse.julialang.org/t/can-i-get-a-code-review-on-this-wrapper-class-inheriting-from-abstractarray/95974>\
**Category:** New to Julia\
**Created:** [March 12, 2023, 7:32pm UTC](https://discourse.julialang.org/t/can-i-get-a-code-review-on-this-wrapper-class-inheriting-from-abstractarray/95974 "2023-03-12T19:32:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bryaan/32/36858_2.png) [@bryaan](https://discourse.julialang.org/u/bryaan)\
**Post date:** [March 12, 2023, 7:32pm UTC](https://discourse.julialang.org/t/can-i-get-a-code-review-on-this-wrapper-class-inheriting-from-abstractarray/95974/1 "2023-03-12T19:32:00Z")

</div>

Can I please get a code review on this wrapper class inheriting from AbstractArray?

```
S = WrappedSeries(5)
S[1, :A] += 1
S[end, :A] += 1

import Base: to_index

mutable struct WrappedSeries <: AbstractArray{Int64,2}
  data::CircularBuffer{Vector{Int64}}
end

function WrappedSeries(length::Int)
  data = CircularBuffer{Vector{Int64}}(length)
  fill!(data, [0, 0])
  WrappedSeries(data)
end

@inline Base.getindex(S::WrappedSeries, i::Int, j::Int) = S.data[i][j]
@inline Base.setindex!(S::WrappedSeries, value, i::Int, j::Int) = S.data[i][j] = value
Base.size(S::WrappedSeries) = (length(S.data), 2)
Base.length(S::WrappedSeries) = length(S.data)
Base.eltype(::Type{WrappedSeries}) = Int64
Base.IndexStyle(::Type{<:WrappedSeries}) = IndexCartesian()
Base.convert(::Type{AbstractArray}, cb::WrappedSeries) = [x for x in cb]

@inline function Base.getindex(S::WrappedSeries, r::Int, c::Symbol)
  S[r, to_index(S, c)]
end

@inline function Base.setindex!(S::WrappedSeries, value, r::Int, c::Symbol)
  S[r, to_index(S, c)] = value
  S
end

function to_index(S::WrappedSeries, s::Symbol)
  @match s begin
    :A => 1
    :B => 2
    _ => throw(ArgumentError("Bad arg"))
  end
end

```
