try this, the implementation is multidimentional

```
struct CircularArray{T,N} <: AbstractArray{T,N} #inherits from AbstractArray
x::AbstractArray{T,N}
function CircularArray(x::AbstractArray{T,N}) where {T,N}
#creates the type only with a vector x
return new{T,N}(x)
end
end
Base.size(A::CircularArray) = size(A.x) #important: use of Base.function
Base.length(A::CircularArray)=length(A.x)
function Base.getindex(A::CircularArray, I::Vararg{Int, N}) where N # implements A[I]
I2 = size(A)
return Base.getindex(A.x,(mod.(I .- 1,I2) .+ 1)...) #this is the magic operation
end
Base.getindex(A::CircularArray, I) = (A[i] for i in I) #A[1:5], for example
function Base.setindex!(A,value,I::Vararg{Int, N}) where N # A[I] = value
return Base.setindex!(A.x,value,(mod.(I .- 1,I2) .+ 1)...)
end
Base.IndexStyle(::Type{CircularArray}) = IndexCartesian()
```

example code:

```
x=reshape(collect(0:15).%4 .+1,(4,4));
y=x'
x1=CircularArray(x)
y1=CircularArray(y)
i=0;j=1;
x1[i,j],y1[i,j]
```

this works in N dimensions:

```
#1-dimentional example
z = 1:15
z2 = CircularArray(z)
z2[16] # 1
z3 = collect(z2[14:16]) #[14,15,1]
```