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

Matthew Johnson matthew at anandabits.com
Tue Jun 28 14:42:42 CDT 2016


> On Jun 28, 2016, at 2:18 PM, Jonathan Hull via swift-evolution <swift-evolution at swift.org> wrote:
> 
> One more question on this.
> 
> How would we handle the opt-out safety for people who are intentionally trying to create an infinite loop?
> 
> I don’t think we can make .until() safely lazy for iterators which have reference semantics and are destructive single-pass, so it has to be eager.  
> If .until() is eager, then .until(false) will fall into an infinite loop before the for-in loop is even run.  

This is an argument against a library solution if iterators have reference semantics.  Any solution that requires eager behavior is not a good solution.

> 
> Maybe there just a way to plug an iterator/sequence directly in, and then silence the warning?  or we could do for-in-until…
 
I don’t think this should be a warning that can be silenced.  I think you are uncovering good reasons to go with a language supported solution.

This wouldn’t need to happen in Swift 3.  There have been other cases where we have adopted a “break it now in anticipation of making it better in the future” policy.  If we conclude that a language solution is warranted and can’t get it into Swift 3 that is ok IMO.  It is still possible to manually iterate infinite sequences.  This wouldn’t be that big a deal given that it is relatively infrequent.

> 
> Thanks,
> Jon
> 
>> On Jun 28, 2016, at 10:51 AM, Dave Abrahams <dabrahams at apple.com <mailto:dabrahams at apple.com>> wrote:
>> 
>>>> 
>>>> This is a reasonable structure, but there are important details missing.
>>>> 
>>>> 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)
> 
> _______________________________________________
> 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/20160628/f3fd751a/attachment.html>


More information about the swift-evolution mailing list