[swift-evolution] [SR-119] AnySequence --> Any*Collection promotion

Austin Zheng austinzheng at gmail.com
Sun Jan 3 03:18:33 CST 2016


Agreed, any proposal would come with an accompanying PR. Since the API itself is pretty straightforward, I don't think this will put any undue burden on the reviewers. 

Austin

> On Jan 3, 2016, at 12:09 AM, Dave Abrahams <dabrahams at apple.com> wrote:
> 
> 
>> On Jan 2, 2016, at 9:44 PM, Austin Zheng via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Hello all,
>> 
>> Currently there exist at least four 'type-erased' sequence/collection types: AnySequence, AnyForwardCollection, AnyBidirectionalCollection, and AnyRandomAccessCollection.
>> 
>> The three Any*Collection types can be conceptually arranged into a 'ladder', in which collections can be constructed unconditionally from collection types above themselves, and conditionally from collection types below themselves. I've put together a little ASCII image of this here: (https://gist.github.com/austinzheng/829425242bef1573b668).
>> 
>> Note that AnySequence doesn't currently fit into this ladder: Any*Collection instances can't easily be constructed from AnySequences. SR-119 (https://bugs.swift.org/browse/SR-119) aims to change that. As per that ticket, I propose that we add three promotion APIs, sketched out as following:
>> 
>> extension AnyForwardCollection {
>>     init?<Element>(_: AnySequence< Element>)
>> }
>> 
>> extension AnyBidirectionalCollection {
>>     init?<Element>(_: AnySequence< Element>)
>> }
>> 
>> extension AnyRandomAccessCollection {
>>     init?<Element>(_: AnySequence< Element>)
>> }
>> 
>> Like their Any*Collection --> Any*Collection antecedents, these initializers construct a new Any*Collection out of an existing AnySequence, but only if the underlying sequence is compatible, and without copying the underlying sequence.
>> 
>> I'll also have to examine SE-0014 (https://github.com/apple/swift-evolution/blob/master/proposals/0014-constrained-AnySequence.md) more closely to see if it has any effects on this proposal.
>> 
>> I plan on submitting a formal proposal at some point (probably by the end of the coming week), but first wish to solicit feedback, opinions, concerns, etc. Thanks for your time.
> 
> My main concern is whether you can implement it, and do so efficiently.  I don’t have a particular reason to think you can’t, but it seems simple enough to check, so IMO such a proposal should come with an implementation.
> 
> -Dave
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160103/1f8c72ff/attachment.html>


More information about the swift-evolution mailing list