Pure vs. impure iterators in Go

12 points by carlana


typesanitizer

I think the terms the author is looking for are restartable and non-restartable.

Using "pure" is confusing -- you can have a restartable iterator over a file on disk (under assumption of no concurrent mutation) and you can have a non-restartable one as well (e.g. if you're modifying a seek cursor tracked by libc for you). However, both of those would be "impure" because you're doing I/O.

mond

Is anyone else horrified that there's no way to tell whether an iterator you're range-ing over twice will continue where you left off or restart from the beginning?

I just know that this is going to end up a source of bugs for people. Say, any situation where someone is first consuming a preamble, and then "everything else" (which silently contains the preamble again).

I don't expect it to come up very often, but I could see it being really hard to debug (or for it to just stay hidden without anyone ever noticing).

I guess what I am saying is that I am so far still not convinced iterators for Go are that much of a value add. (The Seq and Seq2 distinction due to the lack of tuples doesn't help with this.)