I currently have a scenario where a class receives a Tuple of any elements, and I need a method fn(x: to type x as being the Intersection of all types of the elements. I currently am able to do this with a union
class Base[T <: Tuple](tuple: T):
def fn(x: Tuple.Union[T]):
but the semantics of my real problem require this to be an intersection, not union.
But Tuple.Intersection appears to be missing from the stdlib. How come?
The meta-question I’d ask myself is, given a tuple of types (T1, T2), say, then how would I come up with an instance of T1 & T2 to pass to fn?
The tuple value has a T1 and a T2, but neither are nominally the intersection type.
Is the idea to do a runtime type test somewhere before calling fn? So in reality the tuples would have to be of runtime type (T1 & T2, T1 & T2)? Would you be able to work with more precise static types, and use =:=?
EDIT: perhaps the intent is to present an external value x to be somehow vetted / merged / whatever operation against all of the elements of the tuple?
In which case you may be better off defining explicit overloads for each arity of tuple and thus being able to type x as T1 & T2 or T1 & T2 & T3 etc. Or just not bother with a tuple in the first place and use an Iterable[X] and type x as being T <: X for some T.
This also begs the question as to what the operation would be, given the lack of constraints on the types… Equality? Hashing?
Given how open-ended the question is, and the lack of problem context, it’s pointless my speculating further; I’ve have other things to attend to.