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

Dave Abrahams dabrahams at apple.com
Sun Jan 3 02:09:15 CST 2016


> 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 <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 <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 <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/3c64dd2e/attachment.html>


More information about the swift-evolution mailing list