@generated function - iterate over function argument

ConstructionBase.jl getproperties does this with a generated function:

https://github.com/JuliaObjects/ConstructionBase.jl/blob/2044dd59b61c701b66ab43fc4b4326573c126095/src/ConstructionBase.jl#L46-L53

Flatten.jl can choose a specific subset of fields based on types or FieldMetadata.jl tags. However, it doesn’t return a named tuple as it gets a tuple from nested objects that may have the same field names. So it returns a Tuple. But the code is kinda hard to understand…
https://github.com/rafaqz/Flatten.jl/blob/master/src/Flatten.jl#L105-L133

2 Likes