jw3126
February 27, 2025, 11:03am
1
I want to introspect a union type. More concretely I want
a function that takes a type T of the form T = Union{X,Y}
and returns Set((X,Y)). I can do this like X = T.a and Y = T.b.
But that feels like internals. Is there an official way to do this?
I think such manipulations are officially discouraged, with T.a and T.b being the only way to access Union parts.
nsajko
March 1, 2025, 4:23pm
3
Feature request on Julia’s issue tracker on Github:
opened 05:44PM - 05 Feb 24 UTC
types and dispatch
feature
Useful functionality like `Base.typesplit` or `Base.promote_union` may be implem… ented by recursively mapping over the components of a `Union` object. I wonder if it would make sense to provide a public API so users could do that themselves. I guess either of these would be nice:
1. document and support the `a` and `b` fields of a `Union`, or
2. provide some higher level API similar to `mapreduce`, that would take a type instead of a collection, interpreting union components as collection elements