Unpacking struct properties

You can do

Base.iterate(x::A, i = 1) = (i <= fieldcount(A)) ? (getfield(x, i), i + 1) : nothing

but I wouldn’t really recommend it. The struct destructuring syntax is based on names instead of order and thus allows extracting arbitrary subsets of the fields and is insensitive to reordering of the fields.

2 Likes