[swift-evolution] restricting AnySequence.init

Andrew Bennett cacoyi at gmail.com
Fri Jan 1 21:57:50 CST 2016


+1 looks good to me, I also feel like this is an important bug fix. It
would be nice if Swift had some kind of automatic process for type erasure
that delegates all calls the the underlying implementation.

As a more concrete example for why this is important, try running these two
lines in a playground:

print(Array((0...1000000000).suffix(2)))
print(Array(AnySequence(0...1000000000).suffix(2)))


The second line will take a very long time to run.


On Tue, Dec 8, 2015 at 7:50 AM, Dmitri Gribenko via swift-evolution <
swift-evolution at swift.org> wrote:

> On Mon, Dec 7, 2015 at 12:43 PM, Maxim Moiseev via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> Hi all,
>>
>> Here is the proposal to add more constraints to AnySequence.init in order
>> to implement delegation of method calls to the underlying SequnceType
>> implementation.
>>
>> https://github.com/moiseev/swift-evolution/blob/restricted-anyseq/proposals/0008-constrained-AnySequence.md
>>
>> (Including full text of the proposal at the bottom for your convenience).
>>
>> Final goal would be to eventually properly delegate all the calls to
>> `SequenceType` and `CollectionType` methods inside `AnySequence` and
>> `Any${Traversal}Collection`.
>>
>
> Thanks, Max!
>
> I reviewed this proposal with Max offline and it LGTM.  The biggest
> question that we have to answer is if this change is small enough to be
> included in Swift 2.2.  I would say yes, since the only collections that
> are affected by this change are collections that we don't consider valid,
> where the author went an extra mile to declare an improper SubSequence type
> -- and they would stop working anyway once we can constrain the SubSequence
> the way we want.
>
> What does everyone think?
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>
> _______________________________________________
> 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/20160102/7a90a977/attachment.html>


More information about the swift-evolution mailing list