The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
1answer
50 views

Cleanly using PHP Iterator class in Loops - calling first element

I have implemented the Iterator class in PHP and built the follow mandatory methods as follows class I implements Iterator { private $a = []; function __construct(array $a) { ...
0
votes
2answers
95 views

Library design: better to leave potentially destructive feature in with a warning, or cut it out completely?

I recently created a red-black tree in C# to better understand how it works. With it, I implemented an in-order enumerator, however I quickly realized that enumerating a tree can have destructive ...
6
votes
0answers
125 views

Which languages have the best support for stackful coroutines? [closed]

Various languages support (some flavor of) coroutines. One way to discriminate coroutines is whether they are stackful or not (terminology based on Ana Lucia de Moura; Roberto Ierusalimschy (2004). ...
3
votes
3answers
242 views

Interface to enumerate over files

I'm trying to design a generic interface for enumerating over a list files. Each iteration will open a file, allow the consuming code to access the file to perform some task, and then close the file. ...
2
votes
3answers
478 views

Alternatives to foreach iterators involving ref and out

I am trying to make a flexible particle system for my XNA game, and I've got these interfaces: public interface IParticle : IUpdateable { bool Alive { get; } float Percent { get; } } public ...
1
vote
3answers
128 views

Best way to find whether a collection does or does not contain an element with a specific desired quality

It seems to be a very common thing to have to tell whether some list or set contains at least one object matching a given condition, yet my prior searching and reading have never found a satisfactory ...
1
vote
2answers
548 views

Python sorted iterable set, modifiable during iteration

I am looking for a datastructure to handle cycling through a large number of ordered subroutines, some of which are active, most of which are not. I am thinking I need an implementation of a python ...
8
votes
2answers
316 views

What are the advantages of next-iterator over this-iterator?

I don't work too often with Java/C# iterators directly but when I do I always wonder what was the reason to design iterators in "next" fashion. In order to start you have to move iterator, in order ...
1
vote
1answer
170 views

Randomly and uniquely iterating over a range

Say you have a range of values (or anything else) and you want to iterate over the range and stop at some indeterminate point. Because the stopping value could be anywhere in the range, iterating ...
4
votes
3answers
1k views

Is it bad practice to make an iterator that is aware of its own end

For some background of why I am asking this question here is an example. In python the method chain chains an arbitrary number of ranges together and makes them into one without making copies. Here is ...
5
votes
3answers
172 views

Are there languages that expand on the STL's iterator types? [closed]

Many languages use the concept of an iterator. The c++ STL expands on this with input iterators, output iterators, forward, bidirectional, random access and others. As far as I know, these ...
4
votes
3answers
267 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 ...
1
vote
2answers
716 views

Nice iterator naming [closed]

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
622 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 ...
8
votes
1answer
2k 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 ...
9
votes
4answers
383 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 ...
22
votes
4answers
10k 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
378 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
846 views

Question regarding LinkedList in Java

When I was reading a book for SCJP, I came across the following paragraph. A LinkedList is ordered by index position, like ArrayList, except that the elements are doubly-linked to one another. ...
1
vote
2answers
573 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 ...
1
vote
2answers
189 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 ...