<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=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">>>><i class=""> Basically, I added back in a super-minimal protocol to fill the
</i>>>><i class=""> structural gap left by Sequence. I call it “IteratorProvider” and it
</i>>>><i class=""> only has a single function which vends an iterator. Collection
</i>>>><i class=""> adheres to this, and Iterator adheres to it by returning itself. All
</i>>>><i class=""> of the other methods from Sequence remain on Iterator. Thus anyone
</i>>>><i class=""> with API that only needs a single pass would take a IteratorProvider
</i>>>><i class=""> and then work on the iterator it provides.
</i>>><i class="">
</i>>><i class=""> That leaves us back where we are now: people will see that
</i>>><i class=""> IteratorProvider is a simple, universal protocol for both single-and
</i>>><i class=""> multi-pass sequences, write algorithm libraries that depend on
</i>>><i class=""> multi-pass-ness, and test them with the most prevalent examples, which
</i>>><i class=""> happen to be multi pass.
</i>><i class="">
</i>><i class=""> Let me make a quick counter-argument, because I thought about it a
</i>><i class=""> bit, and I don’t think it does have the same problem (especially with
</i>><i class=""> careful/better naming).
</i>><i class="">
</i>><i class=""> The difference is that the ONLY method on IteratorProvider is the one
</i>><i class=""> to get an iterator. There is no map, filter, sort, first, count, etc…
</i>><i class=""> just a way to get a single-pass iterator. This changes the mindset
</i>><i class=""> when using it. You are aware that you are getting a single-pass
</i>><i class=""> iterator.
</i>
Maybe. What's to stop people from extending IteratorProvider?</pre></blockquote><div class=""><br class=""></div></div><div class="">Nothing. But that is true of any protocol. I am ok with individual's extensions. They would have to use that single method to build up from anyway, so presumably they would have to consider the single pass case in their extensions...</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">><i class=""> True, people might try to get the iterator a second time, but we can
</i>><i class=""> make the iteratorProvider method optional (and trying to get an
</i>><i class=""> iterator from an iterator which is spent would return nil)
</i>><i class=""> and then they are forced to deal with the case where it was
</i>><i class=""> single-pass.
</i>
Now you can't loop over the same array multiple times.</pre></blockquote><div class="">I must be missing something. Isn’t that the point?</div></div><div class=""><br class=""></div><div class="">I mean, your version is called “IterableOnce”. Why do you want to iterate on IterableOnce more than once? The point (at least in my mind) is to provide a common interface for things that we want to iterate over a single time. If you want to iterate multiple times, use collection’s interface where you are guaranteed multi-pass.</div><div class=""><br class=""></div><div class="">That said, you actually can loop multiple times for collections by getting a new iterator from the provider (which could point to the same array storage). The optional just forces you to check for the single-pass case.</div><div class=""><br class=""></div><div class="">I have a feeling like I am missing your true meaning here though...</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Jon</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>