You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
This isn't really how indexing works for arrays. Perhaps the solution would be to look for an array type that already allows indexing by keys, and wrap that in a StructArray?
Would it be possible to have elements of multiple types with the same supertype, so that
- the array can be filtered for given type via Array(::Type) (or similar syntax)
The text was updated successfully, but these errors were encountered: