[swift-evolution] [Pitch] Remove destructive consumption from Sequence
Jonathan Hull
jhull at gbis.com
Tue Jun 28 14:18:49 CDT 2016
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.
Maybe there just a way to plug an iterator/sequence directly in, and then silence the warning? or we could do for-in-until...
Thanks,
Jon
> On Jun 28, 2016, at 10:51 AM, Dave Abrahams <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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160628/dbc4bb79/attachment.html>
More information about the swift-evolution
mailing list