Ash Union Calculations
I'm still wrapping my head around polymorphic relationships and was wondering why a calculation on one needs to return a
%Ash.Union{}
?
E.g.
I tried swapping out the return values above for the direct value, e.g. record.checking_account
and that seemed to work, so what value is being added / what function is this playing here? I don't have multiple clauses in my condition yet as I'm still building things out (if that makes a difference). What was also surprising about this is that despite the calculation specifying a union type in the second argument (e.g. AccountImplementation
), it was happy to return just the value. Thanks.Solution:Jump to solution
We don't check that calculation return values match their declaration (for performance reasons)
5 Replies
Solution
We don't check that calculation return values match their declaration (for performance reasons)
Any instance of a union is wrapped in
%Ash.Union{}
Other things might break down the line by not returning a value matching the typeDoes that mean the type declaration is for documentation purposes?
for calculation returns and generic action returns, effectively yes
its used for code generation etc. as well
i.e for types displayed in APIs
we could theoretically validate those values at runtime, but its not really realistic to do. Once the type system releases, we ought to be able to do more on that front 🙂
Very good info, thank you!