<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 Dec 31, 2015, at 8:22 PM, 鄭齊峯 via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">if you try my modification, it will crash.</span></div></blockquote><div><br class=""></div>Only because your Sequence genereates an arithmetic underflow. I don’t understand what point you’re trying to make</div><div><blockquote type="cite" class=""><div class=""><div class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class=""><div class="" style="font-size: 14px;">struct Fib : SequenceType {</div><div class="" style="font-size: 14px;"> </div><div class="" style="font-size: 14px;"> var a: Int</div><div class="" style="font-size: 14px;"> var b: Int</div><div class="" style="font-size: 14px;"> </div><div class="" style="font-size: 14px;"> var limit: Int</div><div class="" style="font-size: 14px;"> </div><div class="" style="font-size: 14px;"> func generate() -> FibGenerator {</div><div class="" style="font-size: 14px;"> return Generator(a: a, b: b, limit: limit)</div><div class="" style="font-size: 14px;"> }</div><div class="" style="font-size: 14px;">}</div><div class="" style="font-size: 14px;"><br class=""></div><div class=""><span class="" style="font-size: 14px;">let c = Multipass(Fib(a: 1, b: -1, limit: 10))</span><br class=""></div><div class=""><span class="" style="font-size: 14px;"><br class=""></span></div><div class=""><span class="" style="font-size: 14px;">A 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><br class=""></div>I think I understand that pretty well, having designed both of those abstractions, but still don’t get your point. Sorry, I’m trying here, but I can’t figure out what you’re trying to tell me.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">/// A `CollectionType` containing the same elements as `Base`, without storing them.</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">///</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">/// - Requires: `Base` supports multiple passes (traversing it does not</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">/// consume the sequence), and `Base.Generator` has value semantics</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">struct</span> Multipass<Base: SequenceType> : <span class="" style="color: rgb(112, 61, 170);">CollectionType</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">var</span> startIndex: <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span><<span class="" style="color: rgb(112, 61, 170);">Base</span>> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> g = <span class="" style="color: rgb(79, 129, 135);">_base</span>.<span class="" style="color: rgb(61, 29, 129);">enumerate</span>().<span class="" style="color: rgb(61, 29, 129);">generate</span>()</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">if</span> <span class="" style="color: rgb(187, 44, 162);">let</span> (idx, val) = g.<span class="" style="color: rgb(61, 29, 129);">next</span>() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span>(index: idx, buffer: val, generator: g)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span>(index: <span class="" style="color: rgb(187, 44, 162);">nil</span>, buffer: <span class="" style="color: rgb(187, 44, 162);">nil</span>, generator: g)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">var</span> endIndex: <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span><<span class="" style="color: rgb(112, 61, 170);">Base</span>> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span>(index: <span class="" style="color: rgb(187, 44, 162);">nil</span>, buffer: <span class="" style="color: rgb(187, 44, 162);">nil</span>, generator: <span class="" style="color: rgb(79, 129, 135);">_base</span>.<span class="" style="color: rgb(61, 29, 129);">enumerate</span>().<span class="" style="color: rgb(61, 29, 129);">generate</span>())</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">subscript</span>(position: <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span><<span class="" style="color: rgb(112, 61, 170);">Base</span>>) -> <span class="" style="color: rgb(112, 61, 170);">Base</span>.<span class="" style="color: rgb(112, 61, 170);">Generator</span>.<span class="" style="color: rgb(112, 61, 170);">Element</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> position.<span class="" style="color: rgb(79, 129, 135);">buffer</span>!</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">init</span>(<span class="" style="color: rgb(187, 44, 162);">_</span> base: <span class="" style="color: rgb(112, 61, 170);">Base</span>) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">_base</span> = base</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> _base: <span class="" style="color: rgb(112, 61, 170);">Base</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">// Note: Requires T.Generator has value semantics</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">struct</span> MultipassIndex<T: SequenceType> : <span class="" style="color: rgb(112, 61, 170);">ForwardIndexType</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">func</span> successor() -> <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> r = <span class="" style="color: rgb(187, 44, 162);">self</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">if</span> <span class="" style="color: rgb(187, 44, 162);">let</span> (idx, val) = r.<span class="" style="color: rgb(79, 129, 135);">generator</span>.<span class="" style="color: rgb(61, 29, 129);">next</span>() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> r.<span class="" style="color: rgb(79, 129, 135);">index</span> = idx</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> r.<span class="" style="color: rgb(79, 129, 135);">buffer</span> = val</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> } <span class="" style="color: rgb(187, 44, 162);">else</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> r.<span class="" style="color: rgb(79, 129, 135);">index</span> = <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> r.<span class="" style="color: rgb(79, 129, 135);">buffer</span> = <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> r</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> index: <span class="" style="color: rgb(112, 61, 170);">Int</span>?</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style=""> </span><span class="" style="color: rgb(187, 44, 162);">var</span><span class="" style=""> buffer: </span>T<span class="" style="">.</span>Generator<span class="" style="">.</span>Element<span class="" style="">?</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style=""> </span><span class="" style="color: rgb(187, 44, 162);">var</span><span class="" style=""> generator: </span>EnumerateSequence<span class="" style=""><</span>T<span class="" style="">>.</span>Generator</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">public</span> <span class="" style="color: rgb(187, 44, 162);">func</span> == <T>(x: <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span><<span class="" style="color: rgb(112, 61, 170);">T</span>>, y: <span class="" style="color: rgb(79, 129, 135);">MultipassIndex</span><<span class="" style="color: rgb(112, 61, 170);">T</span>>) -> <span class="" style="color: rgb(112, 61, 170);">Bool</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> x.<span class="" style="color: rgb(79, 129, 135);">index</span> == y.<span class="" style="color: rgb(79, 129, 135);">index</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);">//===--- An example fibonacci sequence ------------------------------------===//</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="color: rgb(187, 44, 162);">struct</span> FibGenerator : <span class="" style="color: rgb(112, 61, 170);">GeneratorType</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">mutating</span> <span class="" style="color: rgb(187, 44, 162);">func</span> next() -> <span class="" style="color: rgb(112, 61, 170);">Int</span>? {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">let</span> c = <span class="" style="color: rgb(79, 129, 135);">a</span> + <span class="" style="color: rgb(79, 129, 135);">b</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">a</span> = <span class="" style="color: rgb(79, 129, 135);">b</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(79, 129, 135);">b</span> = c</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(79, 129, 135);">a</span> < <span class="" style="color: rgb(79, 129, 135);">limit</span> ? <span class="" style="color: rgb(79, 129, 135);">a</span> : <span class="" style="color: rgb(187, 44, 162);">nil</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> a, b, limit: <span class="" style="color: rgb(112, 61, 170);">Int</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);"><span class="" style="color: rgb(187, 44, 162);">struct</span><span class="" style=""> Fib : </span>SequenceType<span class="" style=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">var</span> limit = <span class="" style="color: rgb(39, 42, 216);">100</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">func</span> generate() -> <span class="" style="color: rgb(79, 129, 135);">FibGenerator</span> {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> <span class="" style="color: rgb(187, 44, 162);">return</span> <span class="" style="color: rgb(79, 129, 135);">Generator</span>(a: <span class="" style="color: rgb(39, 42, 216);">0</span>, b: <span class="" style="color: rgb(39, 42, 216);">1</span>, limit: <span class="" style="color: rgb(79, 129, 135);">limit</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"> }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">}</div></div><div class=""><br class=""></div></div></div><div class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">It's true that <span class="" style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;">ForwardIndexType</span> is also run-through the base one by one but it also correct that getting specific value with specific index.</div><div class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><span class="" style="color: rgb(79, 129, 135);">c</span>[<span class="" style="color: rgb(79, 129, 135);">c</span><span class="" style="">.</span><span class="" style="color: rgb(79, 129, 135);">startIndex</span><span class="" style="">.</span>successor<span class="" style="">().</span>successor<span class="" style="">().</span>successor<span class="" style="">()</span>] // it's a defined behave</div></div></div></blockquote><div><br class=""></div>Again, not sure what you’re trying to say here.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><br class=""></div><div class="" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><br class=""></div><div style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> 於 2016年1月1日 下午12:00 寫道:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Dec 31, 2015, at 7:46 PM, Susan Cheng <<a href="mailto:susan.doggie@gmail.com" class="">susan.doggie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><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. In the code I posted there’s a working example of how a GeneratorType model can conform to Equatable..</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><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=""> </div><div class=""> var a: Int</div><div class=""> var b: Int</div><div class=""> </div><div class=""> var limit: Int</div><div class=""> </div><div class=""> func generate() -> FibGenerator {</div><div class=""> return Generator(a: a, b: b, limit: limit)</div><div class=""> }</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="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:dabrahams@apple.com" target="_blank" class="">dabrahams@apple.com</a>></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. Part of the reason for this is our reluctance to create any distinct protocols with identical syntactic requirements <<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>>. 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 <<a href="https://bugs.swift.org/browse/SR-427" rel="noreferrer" target="_blank" class="">https://bugs.swift.org/browse/SR-427</a>> ;-). 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="">/// consume the sequence), and `Base.Generator` has value semantics<br class="">public struct Multipass<Base: SequenceType where Base.Generator: Equatable> : CollectionType {<br class=""> public var startIndex: MultipassIndex<Base> {<br class=""> var g = _base.generate()<br class=""> return MultipassIndex(buffer: g.next(), generator: g)<br class=""> }<br class=""><br class=""> public var endIndex: MultipassIndex<Base> {<br class=""> return MultipassIndex(buffer: nil, generator: _base.generate())<br class=""> }<br class=""><br class=""> public subscript(position: MultipassIndex<Base>) -> Base.Generator.Element {<br class=""> return position.buffer!<br class=""> }<br class=""><br class=""> public init(_ base: Base) {<br class=""> _base = base<br class=""> }<br class=""><br class=""> var _base: Base<br class="">}<br class=""><br class="">// Note: Requires T.Generator has value semantics<br class="">public struct MultipassIndex<T: SequenceType where T.Generator: Equatable> : ForwardIndexType {<br class=""> public func successor() -> MultipassIndex {<br class=""> var r = self<br class=""> r.buffer = r.generator.next()<br class=""> return r<br class=""> }<br class=""> var buffer: T.Generator.Element?<br class=""> var generator: T.Generator<br class="">}<br class=""><br class="">public func == <T>(x: MultipassIndex<T>, y: MultipassIndex<T>) -> Bool {<br class=""> return x.buffer == nil && y.buffer == nil || x.generator == y.generator<br class="">}<br class=""><br class="">//===--- An example fibonacci sequence ------------------------------------===//<br class="">struct FibGenerator : GeneratorType {<br class=""> mutating func next() -> Int? {<br class=""> let c = a + b<br class=""> a = b<br class=""> b = c<br class=""> return a < limit ? a : nil<br class=""> }<br class=""> var a, b, limit: Int<br class="">}<br class=""><br class=""><br class="">struct Fib : SequenceType {<br class=""> var limit = 1000<br class=""><br class=""> func generate() -> FibGenerator {<br class=""> return Generator(a: 0, b: 1, limit: limit)<br class=""> }<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) -> Bool {<br class=""> 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 class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">-Dave</div></div></blockquote></div><br class="" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><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-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; 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-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span></span><span style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 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-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: AvenirNext-Medium; font-size: 15px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""><div class="">
-Dave
</div>
<br class=""></body></html>