<html><head><meta http-equiv="Content-Type" content="text/html charset=big5"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">if you try my modification, it will crash.<div class=""><br class=""><div class=""><div style="font-size: 14px;" class="">struct Fib : SequenceType {</div><div style="font-size: 14px;" class=""> </div><div style="font-size: 14px;" class=""> var a: Int</div><div style="font-size: 14px;" class=""> var b: Int</div><div style="font-size: 14px;" class=""> </div><div style="font-size: 14px;" class=""> var limit: Int</div><div style="font-size: 14px;" class=""> </div><div style="font-size: 14px;" class=""> func generate() -> FibGenerator {</div><div style="font-size: 14px;" class=""> return Generator(a: a, b: b, limit: limit)</div><div style="font-size: 14px;" class=""> }</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 SequenceType becomes a CollectionType only work by adding a Index. that the most significantly different of sequence and collection.</span></div><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="">/// 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> <span style="color: rgb(187, 44, 162);" class="">struct</span> Multipass<Base: SequenceType> : <span style="color: rgb(112, 61, 170);" class="">CollectionType</span> {</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> <span style="color: rgb(187, 44, 162);" class="">var</span> startIndex: <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span><<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=""> <span style="color: rgb(187, 44, 162);" class="">var</span> g = <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=""> <span style="color: rgb(187, 44, 162);" class="">if</span> <span style="color: rgb(187, 44, 162);" class="">let</span> (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=""> <span style="color: rgb(187, 44, 162);" class="">return</span> <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=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span>(index: <span style="color: rgb(187, 44, 162);" class="">nil</span>, buffer: <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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">public</span> <span style="color: rgb(187, 44, 162);" class="">var</span> endIndex: <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span><<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=""> <span style="color: rgb(187, 44, 162);" class="">return</span> <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span>(index: <span style="color: rgb(187, 44, 162);" class="">nil</span>, buffer: <span style="color: rgb(187, 44, 162);" class="">nil</span>, generator: <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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">public</span> <span style="color: rgb(187, 44, 162);" class="">subscript</span>(position: <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span><<span style="color: rgb(112, 61, 170);" class="">Base</span>>) -> <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> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> 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=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">public</span> <span style="color: rgb(187, 44, 162);" class="">init</span>(<span style="color: rgb(187, 44, 162);" class="">_</span> base: <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=""> <span style="color: rgb(79, 129, 135);" class="">_base</span> = base</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> _base: <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> <span style="color: rgb(187, 44, 162);" class="">struct</span> MultipassIndex<T: SequenceType> : <span style="color: rgb(112, 61, 170);" class="">ForwardIndexType</span> {</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> <span style="color: rgb(187, 44, 162);" class="">func</span> successor() -> <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> r = <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=""> <span style="color: rgb(187, 44, 162);" class="">if</span> <span style="color: rgb(187, 44, 162);" class="">let</span> (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=""> r.<span style="color: rgb(79, 129, 135);" class="">index</span> = idx</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> r.<span style="color: rgb(79, 129, 135);" class="">buffer</span> = val</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> } <span style="color: rgb(187, 44, 162);" class="">else</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> r.<span style="color: rgb(79, 129, 135);" class="">index</span> = <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=""> r.<span style="color: rgb(79, 129, 135);" class="">buffer</span> = <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=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> r</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;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> index: <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 style="color: rgb(0, 0, 0);" class=""> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span style="color: rgb(0, 0, 0);" class=""> buffer: </span>T<span style="color: rgb(0, 0, 0);" class="">.</span>Generator<span style="color: rgb(0, 0, 0);" class="">.</span>Element<span style="color: rgb(0, 0, 0);" class="">?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="color: rgb(0, 0, 0);" class=""> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span style="color: rgb(0, 0, 0);" class=""> generator: </span>EnumerateSequence<span style="color: rgb(0, 0, 0);" class=""><</span>T<span style="color: rgb(0, 0, 0);" class="">>.</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> <span style="color: rgb(187, 44, 162);" class="">func</span> == <T>(x: <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span><<span style="color: rgb(112, 61, 170);" class="">T</span>>, y: <span style="color: rgb(79, 129, 135);" class="">MultipassIndex</span><<span style="color: rgb(112, 61, 170);" class="">T</span>>) -> <span style="color: rgb(112, 61, 170);" class="">Bool</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> x.<span style="color: rgb(79, 129, 135);" class="">index</span> == 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> FibGenerator : <span style="color: rgb(112, 61, 170);" class="">GeneratorType</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">mutating</span> <span style="color: rgb(187, 44, 162);" class="">func</span> next() -> <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=""> <span style="color: rgb(187, 44, 162);" class="">let</span> c = <span style="color: rgb(79, 129, 135);" class="">a</span> + <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=""> <span style="color: rgb(79, 129, 135);" class="">a</span> = <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=""> <span style="color: rgb(79, 129, 135);" class="">b</span> = c</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> <span style="color: rgb(79, 129, 135);" class="">a</span> < <span style="color: rgb(79, 129, 135);" class="">limit</span> ? <span style="color: rgb(79, 129, 135);" class="">a</span> : <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=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> a, b, limit: <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 style="color: rgb(0, 0, 0);" class=""> Fib : </span>SequenceType<span style="color: rgb(0, 0, 0);" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">var</span> limit = <span style="color: rgb(39, 42, 216);" class="">100</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">func</span> generate() -> <span style="color: rgb(79, 129, 135);" class="">FibGenerator</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">return</span> <span style="color: rgb(79, 129, 135);" class="">Generator</span>(a: <span style="color: rgb(39, 42, 216);" class="">0</span>, b: <span style="color: rgb(39, 42, 216);" class="">1</span>, limit: <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=""> }</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 class="">It's true that <span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 11px;" class="">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=""><br class=""></div><div 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 style="color: rgb(0, 0, 0);" class="">.</span><span style="color: rgb(79, 129, 135);" class="">startIndex</span><span style="color: rgb(0, 0, 0);" class="">.</span>successor<span style="color: rgb(0, 0, 0);" class="">().</span>successor<span style="color: rgb(0, 0, 0);" class="">().</span>successor<span style="color: rgb(0, 0, 0);" class="">()</span>] // it's a defined behave</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><br class=""></div><div style=""><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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><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 style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: 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=""><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: 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: 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=""></body></html>