Generic Collections, SubSequences and Overloading
And before long you smack your head against one of the more confusing things about generic collections: a sequence’s
SubSequence
doesn’t necessarily contain the same element type as that sequence. This usually manifests itself in one of those compiler errors that has you yelling “what are you talking about you infernal machine” at the compiler before eventually realizing what you’ve done wrong and sheepishly fixing it.[…]
There’s nothing about this definition that forces the elements of
SubSequence
to be anything specific. Really, this needs awhere
clause on the typealias – something that Swift doesn’t currently support[…] So, in the mean-time, the way around this is to specify any requirements like this as part of the declaration.