-
Couldn't load subscription status.
- Fork 44
Open
Description
Would it be possible to have elements of multiple types with the same supertype, so that
- fields common to all structs in the array can be called via Array.Field.
- the array can be filtered for given type via Array(::Type) (or similar syntax) - If there is an "ID" field common to all structs, this can be used as a key.
abstract type MyType end
struct A<:MyType
ID::String
a::Int
end
struct B<:MyType
ID::String
b::Int
end
X = StructArray( [ A("1",1), A("2",2), B("3",3), B("4",4) ], parentType = MyType, Key_Field = :ID )
X.ID # [1,2,3,4]
X["1"] # A("1",1) select element by Key field (like a dictionary or named array)
X(::A) # [A("1",1), A("2",2)] filter for elements of type A
X(::A).a # [1,2] reference field :a as it is common to elements of type A
X.a # Error not all elements contain this field
Metadata
Metadata
Assignees
Labels
No labels