How do you get all the first elements of a tuple in a struct array?

adata = collect(1:10)
bdata = collect(31:40)
tmp2=StructArray((adata,bdata))

How can I get the numbers 1:10 as if they were an array from the StructArray?

Tuple is a very weird “struct”… usually you have real user defined struct

Not directly replying to the question. But maybe it is better to use instead

tmp3=StructArray((;adata,bdata))

and then write

tmp3.adata # == 1:10
1 Like

oh yeah:

julia> getproperty(tmp2, 1)
10-element Vector{Int64}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

julia> tmp2.:1
10-element Vector{Int64}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
2 Likes

@jling’s solution is the most concise while remaining intuitive and general: component access in structarrays is done with property access.
But if you want something more explicit, then StructArrays.components(tmp2)[1].