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

Matthew Johnson matthew at anandabits.com
Sat May 28 14:25:38 CDT 2016



Sent from my iPad

> On May 28, 2016, at 1:38 PM, Haravikk via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On 27 May 2016, at 15:31, plx via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>>   protocol Sequence {
>>     typealias of<E> == S: Self where S.Iterator.Element == E
>>   }
>> 
>>   // sequence-accepting variant
>>   func doSomething<S:Sequence.of<Foo>>(values: S) { … }
> 
> This is a nice alternative; would it actually need to be declared in the angle brackets? Could it be done as:
> 
> 	func doSomething(values:Sequence.of<Foo>) { … }
> 
> As long as it would work the same as a generic declaration this could be a good way to do it, either that or a SequenceOf type alias as mentioned.

I think I showed both existential and generic variations didn't I?  You certainly could do it either way.  Placing the typealias in the protocol is not a bad idea either!

> 
> 
> Still, I kind of feel like we need to do something with the array type shorthand, but I wonder if perhaps we could just get rid of it altogether, to prevent its use entirely? i.e- all instances of [Foo] can be replaced with Array<Foo>, but we would encourage the use of Sequence.of/SequenceOf/Collection.of/CollectionOf first wherever possible.
> 
> As more types become available that are ArrayLiteralConvertible it seems like we should discourage restriction of a parameter to Array except when a developer explicitly chooses it. This problem will come up with the Dictionary type shorthand as well if Swift gets some kind of Map protocol to abstract it, and we don’t even have a Set-specific syntax so it seems like it may be fairer to remove these shorthands.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160528/c4004f6b/attachment.html>


More information about the swift-evolution mailing list