<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 27 Jun 2016, at 04:56, Jonathan Hull via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Can’t a Sequence be potentially infinite, whereas a collection has a defined count/endIndex? &nbsp;Other than that, I agree with your statement.</div><div class=""><br class=""></div><div class="">Here is what I see as the appropriate structure:</div><div class=""><br class=""></div><div class=""><b class="">Iterator</b>: Single destructive pass, potentially infinite, (should be for-in able)</div><div class=""><b class="">Sequence</b>: Guaranteed non-destructive multi-pass (vends Iterators), potentially infinite, (should be subscript-able, gain most of collection, but lose anything that relies on it ending)</div><div class=""><b class="">Collection</b>: Multi-pass, guaranteed finite, (no changes from current form, except extra inits from Iterator/Sequence with end conditions)</div><div class=""><br class=""></div><div class="">Right now we are allowed to have an infinite sequence, but calling dropLast or non-lazy map will cause an infinite loop. &nbsp;These cases could be made much safer by considering the potentially infinite and finite cases separately...</div></div></div></blockquote></div><br class=""><div class="">This seems pretty reasonable to me, though I'm not sure about subscripting Sequence, I mean you can always add that yourself to sequence types where it makes sense to them that way, but otherwise I think it's best to just keep it simple and leave Sequences as a type that vends iterators over the same values.</div><div class=""><br class=""></div><div class="">Some methods of sequence may need to be moved to iterators though, but in mutating form; things like .dropFirst() to skip elements, .first(where:) for skipping to a matching element and so-on. Iterator should probably also have the .underestimatedCount property so they can give a useful value if it can be known.</div><div class=""><br class=""></div><div class="">But yeah, I think the basic structure of this makes sense, as the potentially destructive nature of sequences doesn't seem that well known in my experience, and I often have to go back and check my code to be sure I've avoid possible destructive usage; I've never thought of trying to use iterators instead, might try changing some methods and see how that goes.</div></body></html>