How to make a struct support subsetting elements 'recursively'

Suppose I have the following:

struct mystuff
  x::Array{Float64,1}
  y::Array{Float64,1}
  mystuff(n) = begin
    s = new(Array{Float64,1}(undef,n),Array{Float64,1}(undef,n))
    return s
  end
  mystuff(x,y) = begin
    s = new(x,y)
    return s
  end
end

check = mystuff([1,2,3],[8,9,10])

How do I make this support subsetting like check2=check[<indexes>] so that the following happens:

julia> check2=check[1:2]
julia> check2.x
2-element Array{Float64,1}:
 1.0
 2.0
julia> check2.y
2-element Array{Float64,1}:
 9.0
 10.0

As one solution, you could override Base.getindex:

julia> import Base: getindex

julia> getindex(s::mystuff, i) = mystuff(s.x[i], s.y[i])
getindex (generic function with 545 methods)

julia> check = mystuff([1,2,3],[8,9,10])
mystuff([1.0, 2.0, 3.0], [8.0, 9.0, 10.0])

julia> check[1:2]
mystuff([1.0, 2.0], [8.0, 9.0])

This is a typical Julia pattern. Use the type system to create specific behavior and override Base or other functions (i.e. add new methods of those functions) locally to support your types.

perfect, thanks