[swift-evolution] [Pre-proposal] Replace [Foo] With CollectionType

Brent Royal-Gordon brent at architechies.com
Tue May 24 17:55:05 CDT 2016


> Better support for existentials (see the generics manifesto, https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md) should obviate the need for any sort of sugar or compiler magic to do this kind of thing.
> 
> typealias AnyCollection<T> = Any<Collection where .Element == T, ...>
> func doSomething(collection: AnyCollection<Foo>)

That isn't really the same thing, though. Any<Collection> is an existential; it introduces indirection which would not be present in the generic version and, in this case, it erases several associated types, potentially introducing type-unsafety as well.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list