> On Jul 20, 2016, at 2:57 PM, Jonathan Hull via swift-evolution > <[email protected]> wrote: > >> > True, people might try to get the iterator a second time, but we can >> > make the iteratorProvider method optional (and trying to get an >> > iterator from an iterator which is spent would return nil) >> > and then they are forced to deal with the case where it was >> > single-pass. >> >> Now you can't loop over the same array multiple times. > I must be missing something. Isn’t that the point? > > 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. > > 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. > > I have a feeling like I am missing your true meaning here though... > > Thanks, > Jon
Right - an iterator instance is single pass, but a method that returns an iterator may be able to make multiple iterators which iterate over the same sequence of values. I still think ideally you can operate on iterators as streams of data directly, rather than requiring a base protocol. I understand how this could cause lots of duplication to have two ‘sequence’ implementations, however. -DW
signature.asc
Description: Message signed with OpenPGP using GPGMail
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
