Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to make a struct support subsetting elements 'recursively'

$
0
0

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

3 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles