The iterator tag has no wiki summary.
3
votes
3answers
189 views
Is there an idiom for a loop that executes some block of instructions between iterations? (In Ruby in particular)
I often need to do some operations in a loop and some other operations between the iterations. A simple example would be collecting words from an array into a string, spelled backwards and separated ...
3
votes
3answers
359 views
Nice iterator naming
How do you name your iterators when you return a begin and an end iterator from a class? Without it sounding clunky, that is.
Example:
typedef std::vector<Idea> Ideas_Type;
...
0
votes
1answer
263 views
PHP, when to use iterators, how to buffer results?
When is it best to use Iterators in PHP, and how can they be implemented to best avoid loading all objects into memory simultaneously?
Do any constructs exist in PHP so that we can queue up results ...
6
votes
1answer
560 views
Why do Java's Iterator and ListIterator point between elements?
The Javadoc for ListIterator says:
A ListIterator has no current element; its cursor position always lies
between the element that would be returned by a call to previous() and
the element ...
7
votes
2answers
190 views
Does an iterator have a non-destructive implied contract?
Let's say I'm designing a custom data structure like a stack or a queue (for example - could be some other arbitrary ordered collection that has the logical equivalent of push and pop methods - ie ...
16
votes
4answers
2k views
Why do iterators in Python raise an exception?
Here's the syntax for iterators in Java (somewhat similar syntax in C#):
Iterator it = sequence.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
Which makes sense. Here's ...
5
votes
3answers
351 views
Is “3 or more use a for” a good rule of thumb?
When do repetitive operations become a code smell? I read this article by Charles Petzold where he suggested this and was wondering what people thought.
0
votes
2answers
326 views
Enumerators vs. returning
I've been reading over the Enumerable module in Ruby, and it contains a few methods that follow the pattern of
enum.foo(n) {|obj| block } → nil
enum.foo(n) → an_enumerator
Which is to say, they ...
3
votes
1answer
294 views
What do you think of this generator syntax? [closed]
I've been working on an ECMAScript dialect for quite some time now and have reached a point where I am comfortable adding new language features. I would love to hear some thoughts and suggestions on ...
1
vote
2answers
155 views
Does anyone else feel that iterator syntax sugar is a must have in a modern language?
I work with C# professionally and I write code like this all the time.
private IEnumerable<Something> GetAlotOfSomething()
{
if (somethingA.IsReady)
yield return somethingA;
if ...