There have been many use cases that I’ve come across where I want to do something like this:
protocol SomeProtocol { }
extension Array: SomeProtocol where Element: SomeProtocol { }
This seems like a something that swift should move toward as it is a “protocol oriented language”. This would enable ease of building new libraries that need to extend collection types and other storage type classes in the standard library.
I have ran into this problem multiple times now. When creating libraries for Thrift and YAML parsing we were forced to create wrapper objects for Array, Set & Dictionary to make then Hashable for Hashable elements; made me feel dirty as the solution seemed so obvious that I couldn’t believe it wasn’t already available.
That being said. This is specifically mentioned as “in scope” for Swift 3 (under Generics). Does that mean a proposal is already available from the internal Swift team? Is it already being developed internally?
···
On Dec 9, 2015, at 12:09 AM, Thane Gill via swift-evolution <swift-evolution@swift.org> wrote:
There have been many use cases that I’ve come across where I want to do something like this:
protocol SomeProtocol { }
extension Array: SomeProtocol where Element: SomeProtocol { }
This seems like a something that swift should move toward as it is a “protocol oriented language”. This would enable ease of building new libraries that need to extend collection types and other storage type classes in the standard library.
I have ran into this problem multiple times now. When creating libraries for Thrift and YAML parsing we were forced to create wrapper objects for Array, Set & Dictionary to make then Hashable for Hashable elements; made me feel dirty as the solution seemed so obvious that I couldn’t believe it wasn’t already available.
That being said. This is specifically mentioned as “in scope” for Swift 3 (under Generics).
Right. We tend to refer to this as "conditional conformance".
Does that mean a proposal is already available from the internal Swift team?
Not yet. I have a general sense of the semantics we need here, but need to work out the implementation model a bit before putting together a proposal.
Is it already being developed internally?
No. When it's being worked on, it will happen on GitHub.
- Doug
···
Sent from my iPhone
On Dec 9, 2015, at 2:18 AM, Kevin Wooten via swift-evolution <swift-evolution@swift.org> wrote:
On Dec 9, 2015, at 12:09 AM, Thane Gill via swift-evolution <swift-evolution@swift.org> wrote:
There have been many use cases that I’ve come across where I want to do something like this:
protocol SomeProtocol { }
extension Array: SomeProtocol where Element: SomeProtocol { }
This seems like a something that swift should move toward as it is a “protocol oriented language”. This would enable ease of building new libraries that need to extend collection types and other storage type classes in the standard library.