How to create a function that uses an object attribute if it exists

It isn’t clear what you mean by attribute.
That isn’t a name of a thing in julia.
I am gettuing maybe you mean a type of a field?

2 ways to do this.
The direct way is to have that field types as Union{Array{Array{Float64}, Nothing}
and then set it to nothing to indicated that it isn’t present.
Which you cna then dispatch on, if you put it into a types argument.

However, needing to do this, is a bit of a code smell.
You might be better off having two differnet types, one with this field and one without.


Though maybe i am misunderstanding the question.
And you are saying you already have two types,
and you want to workout which you have.
In which case you can write multiple methods that dispatch on the type to know

1 Like