3 ms·
basic loops certainly don't go wrong all that often, but once you get to more difficult requirements, the iterator abstraction really helps. Maybe you need to
by chousuke 6y ago
basic loops certainly don't go wrong all that often, but once you get to more difficult requirements, the iterator abstraction really helps.
Maybe you need to iterate over two differently sized datastructures in lockstep, or over a complex nested structure, or accumulate and filter the values, or load the data into a temporary buffer that gets flushed and reused once it fills up, or maybe your data source is infinite, or all of the above.
These are cases where using iterators is significantly safer and notably, more composable.