Skip to main content

Questions tagged [iterators]

For questions about iterators, which provide a way to traverse or iterate over a collection of elements, typically in a sequential manner.

Filter by
Sorted by
Tagged with
3 votes
3 answers
2k views

Why does C++'s unordered_map::erase fully invalidate iterators, not even supporting advancing?

The documentation on C++'s unordered_map::erase states: Removes specified elements from the container. The order of the remaining elements is preserved. (This ...
Luatic's user avatar
  • 330
7 votes
1 answer
418 views

How are coroutines implemented in a tree-walking interpreter?

It seems to me that coroutines and derived abstractions like the iterators and generators are implemented the following way: When returning Move the function's stack frame to the heap Save a pointer ...
Matheus Moreira's user avatar
1 vote
1 answer
259 views

Has there been languages that explicitly document the order of evaluation of high order functions on enumerables?

There are high order function on lists, such as map, find, reduce, in some languages. If the result of one such function is piped into another such function, there are multiple possible evaluation ...
user23013's user avatar
  • 2,850
17 votes
1 answer
940 views

What are "interior iteration" and "exterior iteration"?

Another question refers to the terms "interior iteration" and "exterior iteration", and the comments under an answer suggest some disagreement or confusion about the meanings of ...
kaya3's user avatar
  • 20.8k
7 votes
2 answers
367 views

Why would external iteration require lots of code inlining relative to internal iteration?

In Graydon Hoare's blogpost The Rust I Wanted Had No Future, they state that: Iteration used to be by stack / non-escaping coroutines, which we also called "interior" iteration, as opposed ...
JennyJams's user avatar
  • 687
15 votes
7 answers
3k views

What approaches are there to prevent modifying a collection while iterating over it?

A frequent source of bugs in some languages, is to modify a mutable collection while iterating over it. Appending to a list while iterating over it can cause an infinite loop, while removing from it ...
kaya3's user avatar
  • 20.8k
12 votes
6 answers
601 views

Advantages and disadvantages of different iterator protocols

Many high-level languages have some kind of protocol or interface for iterators, allowing user-defined types to be used in "for-each" loops. A few examples from popular languages: In Java, ...
kaya3's user avatar
  • 20.8k
7 votes
10 answers
363 views

What are some syntax options for iterating over arrays?

What are some different syntax choices for loops that iterate over arrays? Of course, there is the common for loop: ...
cocomac's user avatar
  • 575
7 votes
1 answer
101 views

Should functions like filter and map be members of a class or top-level functions?

In python, the filter and map functions (among others) are top-level (i.e. global) functions which take an iterable as an ...
Ginger's user avatar
  • 2,649