I considered tuples first but it looks like there is no method for subtracting tuple types from other tuples Inverse of NamedTuple.Concat for -- subtraction
Scala apparently has no way to say “remove X type from Y” in any context whether that is in unions or tuple concatenations etc. Once you have gone from Set[A | B] -> Set[A | B | C]
, it is impossible to go back to Set[A | B]
. You cannot express Set[A | B | C] -> Set[A | B]
. I can easily remove all C instances from a Set in the runtime, but I can’t express that this has happened on the typelevel.
I don’t need flow-typing or pattern matching, I just need a return type operator I can use on a function signature to express “everything as the same but simply remove K
”.
Can this be done with a macro? A macro that looks at the current union type, and simply rewrites the entire union but without C
behind the scenes? If we can’t remove K from T, can we rebuild all of T without K?