Overload `[]` operator for custom type

Hi,

I’m wondering is it possible to overload [] operator for my struct:

struct MyStruct
    x::Array{Float32,1}
    y::Array{Float32,1}
end

For example I would like when calling my_var[i] (myvar has type MyStruct) to be equal to summation of member variables at corresponding indexes: MyStruct::x[i] + MyStruct::y[i].
Is that possible?

1 Like

See getindex and setindex!.

3 Likes