Custom array with padding through a view

Can you explain what you mean by this? In what way is Julia not “tricked?”

Let’s set up a type and a convenient constructor:

julia> struct MyVec{T} v::Vector{T} end

julia> Base.getindex(::Type{MyVec}, x...) = MyVec([x...])

julia> xs = MyVec[1,2,3]
MyVec{Int64}([1, 2, 3])

Now set up some behaviors you expect vectors to have:

julia> Base.length(v::MyVec) = 3length(v.v)

julia> Base.getindex(v::MyVec, i) = begin
           @assert 1 ≤ i ≤ length(v) "Please be considerate"
           if isodd((i-1)÷length(v.v))  v.v[mod1(i, length(v.v))]
           else  v.v[length(v.v) - mod1(i, length(v.v))+1]
           end
       end

julia> length(xs)
9

julia> [xs[i] for i=1:length(xs)]
9-element Vector{Int64}:
 3
 2
 1
 1
 2
 3
 3
 2
 1

You can also set up iteration utilities like so:

julia> Base.iterate(v::MyVec, n=1) = n ≤ length(v) ? (v[n], n+1) : nothing

julia> (xs...,)
(3, 2, 1, 1, 2, 3, 3, 2, 1)

And of course, for size:

julia> Base.size(v::MyVec) = (length(v),)

julia> size(xs)
(9,)

Sky’s the limit! (just wait until you hit OffsetArrays :wink:)