Friday, January 8, 2016

Generic Collections, SubSequences and Overloading

Airspeed Velocity:

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 a where 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.

Comments RSS · Twitter

Leave a Comment