The tag has no wiki summary.

learn more… | top users | synonyms

0
votes
1answer
57 views

What is the term of property when `succ` is defined? [closed]

The first fact -- C++ for example has operator ++ for ints, which let's you quasi iterate over integers. Starting from 0, you can get 1, 2, 3, 4, ... and so on. The second fact -- take for example a ...
4
votes
3answers
201 views

Java & REST API: How do I check for duplicate before inserting record?

I am developing an application in Java to parse and upload records from a CSV to an online database, via a REST API. While I know for sure that there are no duplicate records in each CSV file, I ...
1
vote
2answers
92 views

Complex iterators in C

note: this was originally asked on SO. Part of my current project involves iterating over sequences that don't necessarily exist. For example, I have something similar to a relational database in ...
5
votes
1answer
249 views

In Java, why does (unsorted) Set implement Iterable, but SortedMap does not?

There are two aspects to this question that I felt were too closely related to ask as separate questions. Why doesn't SortedMap implement Iterable<Map.Entry<K,V>>? If you need to ...
3
votes
4answers
1k views

What do you call an iterator that returns the current, previous and next siblings of each node of a list? [closed]

What do you call an iterator that given a list [a, b, c], returns an object of the form { prev, curr, next } for each iteration? e.g, (? === undefined) { prev: ?, curr: a, next: b } { prev: a, curr: ...
3
votes
1answer
286 views

Why is iterating through List<T> more expensive than iterating through Array in .NET?

According to the answers in this post, List<T> is backed by an Array. According to this article, list iteration is considerably slower than array iteration. If Lists are arrays 'under the ...
0
votes
2answers
185 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
96 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
144 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
259 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
717 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
136 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
652 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
429 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
192 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
2k 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
175 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
278 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
778 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; ...
4
votes
4answers
2k views

C++ Iterator lifetime and detecting invalidation

Based on what's considered idiomatic in C++11: should an iterator into a custom container survive the container itself being destroyed? should it be possible to detect when an iterator becomes ...
0
votes
1answer
654 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
403 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 ...
25
votes
4answers
11k 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
382 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
856 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
579 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
193 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 ...