<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="">I see what you’ve done, now, after diffing your code with mine. &nbsp;That’s a very nice improvement; it generalizes to cover more Sequences and doesn’t require an Equatable generator. &nbsp;Great job!<div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 9:30 PM, Susan Cheng &lt;<a href="mailto:susan.doggie@gmail.com" class="">susan.doggie@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">I didn't explain correctly.<div class=""><br class=""></div><div class="">let's take this:</div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class="">let&nbsp;</span><span style="background-color:rgba(255,255,255,0);font-size:small" class="">c = Multipass(Fib(a: 1, b: -1, limit: 10))</span></div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class=""><br class=""></span></div><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class="">this sequences should have results with [1, -1, 0, -1, -1, ...]</span></div></div></blockquote></div><div><blockquote type="cite" class=""><div class=""><div class=""><span style="background-color:rgba(255,255,255,0);font-size:small" class="">So is c.startIndex.successor() equal to&nbsp;</span><font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class="">c.startIndex.successor().successor().successor()??<span class=""></span></span></font></div><div class=""><br class="">Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; 於 2016年1月1日星期五 寫道:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 8:22 PM, 鄭齊峯 via swift-evolution &lt;<a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><span style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">if you try my&nbsp;modification, it will crash.</span></div></blockquote><div class=""><br class=""></div>Only because your Sequence genereates an arithmetic underflow.&nbsp; I don’t understand what point you’re trying to make</div><div class=""><blockquote type="cite" class=""><div class=""><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""><div class=""><div style="font-size:14px" class="">struct Fib : SequenceType {</div><div style="font-size:14px" class="">&nbsp; &nbsp;&nbsp;</div><div style="font-size:14px" class="">&nbsp; &nbsp; var a: Int</div><div style="font-size:14px" class="">&nbsp; &nbsp; var b: Int</div><div style="font-size:14px" class="">&nbsp; &nbsp;&nbsp;</div><div style="font-size:14px" class="">&nbsp; &nbsp; var limit: Int</div><div style="font-size:14px" class="">&nbsp; &nbsp;&nbsp;</div><div style="font-size:14px" class="">&nbsp; &nbsp; func generate() -&gt; FibGenerator {</div><div style="font-size:14px" class="">&nbsp; &nbsp; &nbsp; &nbsp; return Generator(a: a, b: b, limit: limit)</div><div style="font-size:14px" class="">&nbsp; &nbsp; }</div><div style="font-size:14px" class="">}</div><div style="font-size:14px" class=""><br class=""></div><div class=""><span style="font-size:14px" class="">let c = Multipass(Fib(a: 1, b: -1, limit: 10))</span><br class=""></div><div class=""><span style="font-size:14px" class=""><br class=""></span></div><div class=""><span style="font-size:14px" class="">A&nbsp;SequenceType becomes a CollectionType only work by adding a Index. that the most significantly different of sequence and collection.</span></div></div></div></div></blockquote><div class=""><br class=""></div>I think I understand that pretty well, having designed both of those abstractions, but still don’t get your point.&nbsp; Sorry, I’m trying here, but I can’t figure out what you’re trying to tell me.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div class=""><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">/// A `CollectionType` containing the same elements as `Base`, without storing them.</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">///</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">/// - Requires: `Base` supports multiple passes (traversing it does not</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">/// &nbsp; consume the sequence), and `Base.Generator` has value semantics</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">struct</span>&nbsp;Multipass&lt;Base: SequenceType&gt; :&nbsp;<span style="color:rgb(112,61,170)" class="">CollectionType</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;startIndex:&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&lt;<span style="color:rgb(112,61,170)" class="">Base</span>&gt; {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;g =&nbsp;<span style="color:rgb(79,129,135)" class="">_base</span>.<span style="color:rgb(61,29,129)" class="">enumerate</span>().<span style="color:rgb(61,29,129)" class="">generate</span>()</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">if</span>&nbsp;<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;(idx, val) = g.<span style="color:rgb(61,29,129)" class="">next</span>() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>(index: idx, buffer: val, generator: g)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>(index:&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span>, buffer:&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span>, generator: g)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;endIndex:&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&lt;<span style="color:rgb(112,61,170)" class="">Base</span>&gt; {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>(index:&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span>, buffer:&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span>, generator:&nbsp;<span style="color:rgb(79,129,135)" class="">_base</span>.<span style="color:rgb(61,29,129)" class="">enumerate</span>().<span style="color:rgb(61,29,129)" class="">generate</span>())</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">subscript</span>(position:&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&lt;<span style="color:rgb(112,61,170)" class="">Base</span>&gt;) -&gt;&nbsp;<span style="color:rgb(112,61,170)" class="">Base</span>.<span style="color:rgb(112,61,170)" class="">Generator</span>.<span style="color:rgb(112,61,170)" class="">Element</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;position.<span style="color:rgb(79,129,135)" class="">buffer</span>!</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">init</span>(<span style="color:rgb(187,44,162)" class="">_</span>&nbsp;base:&nbsp;<span style="color:rgb(112,61,170)" class="">Base</span>) {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(79,129,135)" class="">_base</span>&nbsp;= base</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;_base:&nbsp;<span style="color:rgb(112,61,170)" class="">Base</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">// Note: Requires T.Generator has value semantics</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">struct</span>&nbsp;MultipassIndex&lt;T: SequenceType&gt; :&nbsp;<span style="color:rgb(112,61,170)" class="">ForwardIndexType</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">func</span>&nbsp;successor() -&gt;&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;r =&nbsp;<span style="color:rgb(187,44,162)" class="">self</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">if</span>&nbsp;<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;(idx, val) = r.<span style="color:rgb(79,129,135)" class="">generator</span>.<span style="color:rgb(61,29,129)" class="">next</span>() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.<span style="color:rgb(79,129,135)" class="">index</span>&nbsp;= idx</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.<span style="color:rgb(79,129,135)" class="">buffer</span>&nbsp;= val</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;<span style="color:rgb(187,44,162)" class="">else</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.<span style="color:rgb(79,129,135)" class="">index</span>&nbsp;=&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r.<span style="color:rgb(79,129,135)" class="">buffer</span>&nbsp;=&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;r</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;index:&nbsp;<span style="color:rgb(112,61,170)" class="">Int</span>?</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)" class=""><span class="">&nbsp; &nbsp;&nbsp;</span><span style="color:rgb(187,44,162)" class="">var</span><span class="">&nbsp;buffer:&nbsp;</span>T<span class="">.</span>Generator<span class="">.</span>Element<span class="">?</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)" class=""><span class="">&nbsp; &nbsp;&nbsp;</span><span style="color:rgb(187,44,162)" class="">var</span><span class="">&nbsp;generator:&nbsp;</span>EnumerateSequence<span class="">&lt;</span>T<span class="">&gt;.</span>Generator</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:rgb(187,44,162)" class="">public</span>&nbsp;<span style="color:rgb(187,44,162)" class="">func</span>&nbsp;== &lt;T&gt;(x:&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&lt;<span style="color:rgb(112,61,170)" class="">T</span>&gt;, y:&nbsp;<span style="color:rgb(79,129,135)" class="">MultipassIndex</span>&lt;<span style="color:rgb(112,61,170)" class="">T</span>&gt;) -&gt;&nbsp;<span style="color:rgb(112,61,170)" class="">Bool</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;x.<span style="color:rgb(79,129,135)" class="">index</span>&nbsp;== y.<span style="color:rgb(79,129,135)" class="">index</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)" class="">//===--- An example fibonacci sequence ------------------------------------===//</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class=""><span style="color:rgb(187,44,162)" class="">struct</span>&nbsp;FibGenerator :&nbsp;<span style="color:rgb(112,61,170)" class="">GeneratorType</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">mutating</span>&nbsp;<span style="color:rgb(187,44,162)" class="">func</span>&nbsp;next() -&gt;&nbsp;<span style="color:rgb(112,61,170)" class="">Int</span>? {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">let</span>&nbsp;c =&nbsp;<span style="color:rgb(79,129,135)" class="">a</span>&nbsp;+&nbsp;<span style="color:rgb(79,129,135)" class="">b</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(79,129,135)" class="">a</span>&nbsp;=&nbsp;<span style="color:rgb(79,129,135)" class="">b</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(79,129,135)" class="">b</span>&nbsp;= c</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;<span style="color:rgb(79,129,135)" class="">a</span>&nbsp;&lt;&nbsp;<span style="color:rgb(79,129,135)" class="">limit</span>&nbsp;?&nbsp;<span style="color:rgb(79,129,135)" class="">a</span>&nbsp;:&nbsp;<span style="color:rgb(187,44,162)" class="">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;a, b, limit:&nbsp;<span style="color:rgb(112,61,170)" class="">Int</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)" class=""><span style="color:rgb(187,44,162)" class="">struct</span><span class="">&nbsp;Fib :&nbsp;</span>SequenceType<span class="">&nbsp;{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">var</span>&nbsp;limit =&nbsp;<span style="color:rgb(39,42,216)" class="">100</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px" class="">&nbsp;&nbsp; &nbsp;<br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">func</span>&nbsp;generate() -&gt;&nbsp;<span style="color:rgb(79,129,135)" class="">FibGenerator</span>&nbsp;{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)" class="">return</span>&nbsp;<span style="color:rgb(79,129,135)" class="">Generator</span>(a:&nbsp;<span style="color:rgb(39,42,216)" class="">0</span>, b:&nbsp;<span style="color:rgb(39,42,216)" class="">1</span>, limit:&nbsp;<span style="color:rgb(79,129,135)" class="">limit</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">&nbsp; &nbsp; }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="">}</div></div><div class=""><br class=""></div></div></div><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">It's true that&nbsp;<span style="color:rgb(112,61,170);font-family:Menlo;font-size:11px" class="">ForwardIndexType</span>&nbsp;is also run-through the base one by one but it also correct that getting specific value with specific index.</div><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""></div><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><span style="color:rgb(79,129,135)" class="">c</span>[<span style="color:rgb(79,129,135)" class="">c</span><span class="">.</span><span style="color:rgb(79,129,135)" class="">startIndex</span><span class="">.</span>successor<span class="">().</span>successor<span class="">().</span>successor<span class="">()</span>] // it's a defined behave</div></div></div></blockquote><div class=""><br class=""></div>Again, not sure what you’re trying to say here.</div><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><br class=""></div><div style="font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)" class=""><br class=""></div><div style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class="">Dave Abrahams &lt;<a href="javascript:_e(%7B%7D,'cvml','dabrahams@apple.com');" target="_blank" class="">dabrahams@apple.com</a>&gt; 於 2016年1月1日 下午12:00 寫道:</div><br class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class=""><br class="">On Dec 31, 2015, at 7:46 PM, Susan Cheng &lt;<a href="javascript:_e(%7B%7D,'cvml','susan.doggie@gmail.com');" target="_blank" class="">susan.doggie@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">How GeneratorType confirm to Equatable??</div></div></div></blockquote><div class=""><br class=""></div>I don’t understand the question.&nbsp; In the code I posted there’s a working example of how a GeneratorType model can conform to Equatable..</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">struct Fib : SequenceType {</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; var a: Int</div><div class="">&nbsp; &nbsp; var b: Int</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; var limit: Int</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; func generate() -&gt; FibGenerator {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; return Generator(a: a, b: b, limit: limit)</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">let c = Multipass(Fib(a: 1, b: -1, limit: 10))</div><div class=""><br class=""></div><div class="">-Susan</div><div class=""><br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-01-01 11:17 GMT+08:00 Dave Abrahams<span class="">&nbsp;</span><span dir="ltr" class="">&lt;<a href="javascript:_e(%7B%7D,'cvml','dabrahams@apple.com');" target="_blank" class="">dabrahams@apple.com</a>&gt;</span>:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">FWIW, Indexable is an implementation artifact that will go away when Swift’s generics system is improved.<br class=""><br class="">But if your real objection is that you have to come up with an Index and a subscripting operator, I can understand that.&nbsp; Part of the reason for this is our reluctance to create any distinct protocols with identical syntactic requirements &lt;<a href="http://news.gmane.org/find-root.php?message_id=2A3E0C76-1C88-4752-8A70-AA64BB14223A@apple.com" rel="noreferrer" target="_blank" class="">http://news.gmane.org/find-root.php?message_id=2A3E0C76-1C88-4752-8A70-AA64BB14223A@apple.com</a>&gt;.&nbsp; To justify having a separate multi-pass sequence protocol, there would have to be a significant/important class of multi-pass sequences for which CollectionType was unimplementable without serious costs.<br class=""><br class="">In principle there’s a way to ease the pain of creating CollectionType conformances for multipass SequenceTypes…if only it didn’t crash the compiler &lt;<a href="https://bugs.swift.org/browse/SR-427" rel="noreferrer" target="_blank" class="">https://bugs.swift.org/browse/SR-427</a>&gt; ;-).&nbsp; Here’s a variation that uses a generic adapter instead of a protocol conformance declaration:<br class=""><br class="">/// A `CollectionType` containing the same elements as `Base`, without storing them.<br class="">///<br class="">/// - Requires: `Base` supports multiple passes (traversing it does not<br class="">///&nbsp; &nbsp;consume the sequence), and `Base.Generator` has value semantics<br class="">public struct Multipass&lt;Base: SequenceType where Base.Generator: Equatable&gt; : CollectionType {<br class="">&nbsp; public var startIndex: MultipassIndex&lt;Base&gt; {<br class="">&nbsp; &nbsp; var g = _base.generate()<br class="">&nbsp; &nbsp; return MultipassIndex(buffer: g.next(), generator: g)<br class="">&nbsp; }<br class=""><br class="">&nbsp; public var endIndex: MultipassIndex&lt;Base&gt; {<br class="">&nbsp; &nbsp; return MultipassIndex(buffer: nil, generator: _base.generate())<br class="">&nbsp; }<br class=""><br class="">&nbsp; public subscript(position: MultipassIndex&lt;Base&gt;) -&gt; Base.Generator.Element {<br class="">&nbsp; &nbsp; return position.buffer!<br class="">&nbsp; }<br class=""><br class="">&nbsp; public init(_ base: Base) {<br class="">&nbsp; &nbsp; _base = base<br class="">&nbsp; }<br class=""><br class="">&nbsp; var _base: Base<br class="">}<br class=""><br class="">// Note: Requires T.Generator has value semantics<br class="">public struct MultipassIndex&lt;T: SequenceType where T.Generator: Equatable&gt; : ForwardIndexType {<br class="">&nbsp; public func successor() -&gt; MultipassIndex {<br class="">&nbsp; &nbsp; var r = self<br class="">&nbsp; &nbsp; r.buffer = r.generator.next()<br class="">&nbsp; &nbsp; return r<br class="">&nbsp; }<br class="">&nbsp; var buffer: T.Generator.Element?<br class="">&nbsp; var generator: T.Generator<br class="">}<br class=""><br class="">public func == &lt;T&gt;(x: MultipassIndex&lt;T&gt;, y: MultipassIndex&lt;T&gt;) -&gt; Bool {<br class="">&nbsp; return x.buffer == nil &amp;&amp; y.buffer == nil || x.generator == y.generator<br class="">}<br class=""><br class="">//===--- An example fibonacci sequence ------------------------------------===//<br class="">struct FibGenerator : GeneratorType {<br class="">&nbsp; mutating func next() -&gt; Int? {<br class="">&nbsp; &nbsp; let c = a + b<br class="">&nbsp; &nbsp; a = b<br class="">&nbsp; &nbsp; b = c<br class="">&nbsp; &nbsp; return a &lt; limit ? a : nil<br class="">&nbsp; }<br class="">&nbsp; var a, b, limit: Int<br class="">}<br class=""><br class=""><br class="">struct Fib : SequenceType {<br class="">&nbsp; var limit = 1000<br class=""><br class="">&nbsp; func generate() -&gt; FibGenerator {<br class="">&nbsp; &nbsp; return Generator(a: 0, b: 1, limit: limit)<br class="">&nbsp; }<br class="">}<br class=""><br class="">//===--- Adapt Fib for use with Multipass ---------------------------------===//<br class="">extension FibGenerator : Equatable {}<br class="">func == (x: Fib.Generator, y: Fib.Generator) -&gt; Bool {<br class="">&nbsp; return x.a == y.a<br class="">}<br class=""><br class="">//===--- Demonstration ----------------------------------------------------===//<br class="">let c = Multipass(Fib())<br class="">print(c.first)<br class="">print(c.count)<br class="">print(c.lazy.map { $0 + 1 })<br class=""></blockquote></div><br class=""></div></div></div></blockquote></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">-Dave</div></div></blockquote></div><br style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2iUag6Z9T-2BqnrsD8bD7y5-2BwDLHvVHWyCxrqs-2BCIjfPaLjobBqm7cY1WQl-2BrQDc-2BOJX1jkgJnRxMlpgGZ2bampgnhGR9dZy8ODz-2B7c3KVgCDEFZF5bhuC4V8AjfQ8rJBU3q1z8tHXx6SdJ5BJArqzxRShi8fy3KF6qRPQAMqHoL1FXY0Y6gZLA1Slikovs8fdpA-3D" alt="" width="1" height="1" border="0" style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important" class=""><span style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class=""><span class="">&nbsp;</span></span><span style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">_______________________________________________</span><br style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">swift-evolution mailing list</span><br style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="javascript:_e(%7B%7D,'cvml','swift-evolution@swift.org');" style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">swift-evolution@swift.org</a><br style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:AvenirNext-Medium;font-size:15px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""><div class="">
-Dave
</div>
<br class=""></div></blockquote></div>
</div></blockquote></div><br class=""><div class="">
-Dave

</div>
<br class=""></div></body></html>