Skip to content

Generics, extensions, and where clauses: 😱

While trying to implement something completely different and unrelated to the code in this post, I found myself thinking really hard about the combination of Swift generics, protocols, and protocol extensions. But that is not the theme of this post.

But, usually one thing leads to another. At least, that’s what happens usually when I think hard about something: I end up figuring out something completely different. In this case, I’ve just noticed this:

From a purely grammatical point of view, the code makes perfect sense, but I am not sure if there is a real use case for it, at least a use case than can not be solved applying traditional polymorphism (i.e. using interfaces/protocols the way your favourite deity meant them to be used), but well, there it is.

And here is the playground, just in case: GenericsExtensions.playground

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *