Structural Sum Types (used to be Anonymous Union Types)

Does not really help, because to my understanding you then would have to convert all possible input to a common type, so I would have to convert all single items to sequences of items (e.g. by letting them conform to Sequence, but then still an iterator has to be initialized for each item). You can do that, but besides efficiency that feels like programming around a deficiency of the language which is exactly the “missing” sum types.

(It reminds me of using optionals as empty sequences to allow for optional chains in for-in loops which I really “need” in my XML processing — if I do not want to use forEach which is commonly seen as bad habit and also has some real disadvantages. It is those edge cases where I feel Swift could be more “streamlined”: Swift is such a nice language, it is a pity that in those cases you have to resort to strange or discouraged patterns.)

1 Like