[swift-evolution] [Pitch] Remove destructive consumption from Sequence

Dave Abrahams dabrahams at apple.com
Fri Jul 1 18:00:08 CDT 2016


on Tue Jun 28 2016, Jonathan Hull <swift-evolution at swift.org> wrote:

>> On Jun 28, 2016, at 10:51 AM, Dave Abrahams <dabrahams at apple.com> wrote:
>> 
>>>> 1. Presumably these are all for-in-able.  What makes something
>>>>  for-in-able?
>>> 
>>> I would think the potentially infinite should require for-in-until
>>> (even if you explicitly set until to false to create an infinite
>>> loop), but collection would allow for-in (with optional until).  That
>>> way you have to acknowledge the possibility of an infinite
>>> sequence/iterator.
>> 
>> Are you proposing a new language feature?  We could also do this with
>> 
>>    for i in allIntegers.until(isPrime)
>
> I was, but I think I would be ok with this too, as long as the
> compiler caught the issue and suggested a fix.  The key is that we are
> forced to deal with the possibility of an infinite sequence/iterator.
> Also:
>
> for i in infSequence.maxLoops(3000)  //or a better name for this idea

This is already:


  for i in infSequence.prefix(3000) {

  }

>
>
> Thanks,
> Jon
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>

-- 
Dave



More information about the swift-evolution mailing list