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.
Best,
Austin_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution