Skip to main content

Questions tagged [iterator]

Filter by
Sorted by
Tagged with
1 vote
2 answers
477 views

I'm creating a class representation of a mathematical tuple (or simply, an ordered set of numbers). Being a list-like object that could benefit from an iterator representation, I have decided to give ...
Angel E.'s user avatar
  • 129
2 votes
2 answers
3k views

I've had a question for a while. I know that the Array prototype method filter is generally preferred over forEach, and I believe it is typically faster at the job as well. But what about if I have ...
Michael Jay's user avatar
1 vote
0 answers
191 views

I'm trying to understand the following description of implementing the visitor pattern with an internal iterator. It is from the GoF's Design Pattern Elements of Reusable Object-Oriented Software book ...
Yang's user avatar
  • 119
1 vote
3 answers
1k views

Imagine you have to process each row in a large table. For every single row you have to download some data from a web service and store it in a different database. Loading all rows at once into the ...
user avatar
3 votes
3 answers
533 views

Suppose someone designs an indexable iterator class, i.e. an iterator that supports __getitem__ for (non-negative) integer indexes such as the following: In [1] it = indexed_iter("abcdefghij"...
gsakkis's user avatar
  • 413
0 votes
1 answer
627 views

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
scttrbrn's user avatar
  • 103
5 votes
3 answers
1k views

I'm trying to deepen my understanding on this, the only thing I know for sure is that Iterator is an interface in Java. I've been reading CS literature, for example here and here and looking for ...
Amos Cappellaro's user avatar
3 votes
2 answers
861 views

In the "Structure" section of the Iterator design pattern, the book Design Patterns: Elements of Reusable Object-Oriented Software defines the Iterator class with four basic operations: First, Next, ...
Géry Ogam's user avatar
2 votes
0 answers
134 views

I want to loop over a number of rows in a database and I have implemented an object in order to access the rows. Now when using this object I am not sure about the best practice. Implementing an ...
Lucas's user avatar
  • 129
2 votes
4 answers
2k views

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
h23's user avatar
  • 131
1 vote
1 answer
241 views

I am working on creating iterators, for strings, lists, trees, graphs, and potentially other things. First a side note. I have a string data type in my engine. The string is implemented as a bunch of ...
Lance Pollard's user avatar
0 votes
2 answers
117 views

Generally, we are looking to create a logging framework that can target human readable output as well as various structured data formats. So, a goal is minimizing code duplication in packaging the ...
John's user avatar
  • 109
17 votes
4 answers
8k views

I am learning for an exam and I have a question which I am struggling to give and answer for. Why does no iterator base class exist all other iterators inherit from? My guess my teacher is ...
jnt's user avatar
  • 183
1 vote
0 answers
1k views

While studying the visitor design pattern i found this phrase: You can use Visitor along with Iterator to traverse a complex data structure and execute some operation over its elements, even if they ...
Zethel's user avatar
  • 27
3 votes
2 answers
141 views

For example, I have a for loop, which element 0 has additional function to run compared with other elements, my question is, should the additional function be: 1.place inside for loop for(int i=0;i&...
ocomfd's user avatar
  • 5,760
0 votes
2 answers
236 views

Along the lines of How to Simulate Control-Flow without using Control-Flow Primitives, I am wondering how to simulate return from a function. Given an example setup like this: console.log(a(10)) ...
Lance Pollard's user avatar
3 votes
1 answer
1k views

I'm developing a program where twice I've found the solution to a problem was to use hash tables with iterators as keys and some other arbitrary type as the value. I found my self using this pattern ...
Krupip's user avatar
  • 1,347
8 votes
1 answer
19k views

In the Google C++ Style Guide it says: Preincrement and Predecrement Use prefix form (++i) of the increment and decrement operators with iterators and other template objects. When a ...
robert bristow-johnson's user avatar
-1 votes
1 answer
380 views

I'd like to better understand Iterator/Range design decisions (focusing on InputIterators). Basically, this is the java model: while (iter.hasNext()) { Object o = iter.next(); // do ...
geza's user avatar
  • 137
18 votes
1 answer
3k views

Is it ok to add deferred assertions like this var actualKittens = actualKittens.Select(kitten => { Assert.IsСute(kitten); return kitten }); Why? So I can iterate just once even with ...
SerG's user avatar
  • 502
6 votes
1 answer
3k views

The other day I was playing around with an experiment and I had a for loop something like so: for (Node node : children) { // do stuff with node ... } And then I changed it to do this: for (Node ...
JimmyJames's user avatar
  • 31.1k
4 votes
4 answers
3k views

Let's suppose there is a base object class - let it be called Object - and a list<Object> container. There are many child classes of Object - Child1, Child2 etc.. They all are stored in the ...
olegst's user avatar
  • 179
1 vote
0 answers
283 views

Feel free to correct my history, but as far as I understand it, Rx and the Reactive Manifesto trace their roots back to C# and its Reactive Extensions, which is uses push (callback-based) messaging, ...
concat's user avatar
  • 517
34 votes
6 answers
24k views

I just realized that in Python, if one writes for i in a: i += 1 The elements of the original list a will actually not be affect at all, since the variable i turns out to just be a copy of the ...
xji's user avatar
  • 791
8 votes
2 answers
3k views

I have been wondering what it is that makes the Iterator special when compared to other similar constructs, and that made the Gang of Four list it as a design pattern. The Iterator is based on ...
Frank Puffer's user avatar
  • 6,459
3 votes
0 answers
111 views

I am implementing a certain algorithm that works like this: Create a closed contour (list) of elements in a matrix, where closed means that the last element is adjacent (by row, column) to the first. ...
bright-star's user avatar
2 votes
3 answers
2k views

What does these UML diagram arrows mean in Iterator pattern that are drawn from ConcreteAggregate to ConcreteIterator and backwards. I have looked thorough the legend (notations) of UML diagrams, but ...
Narek's user avatar
  • 1,153
4 votes
3 answers
403 views

The title pretty much speaks for itself, but I'll provide the current decision I am facing. I am migrating python code towards the use of generators. The current code looks like this: ... l = ...
nathdwek's user avatar
  • 271
26 votes
1 answer
4k views

The questions are: Do generators break the functional programming paradigm? Why or why not? If yes, can generators be used in functional programming and how? Consider the following: function * ...
Pete's user avatar
  • 1,247
2 votes
3 answers
604 views

On stackoverflow I asked, what is the preferred way to expose custom STL-style iteration?. The answer seems to be to implement twelve functions: six members, six non-members (perhaps using some ...
Ðаn's user avatar
  • 584
3 votes
2 answers
230 views

Sometimes we meet a situation where we should iterate (or map) over a collection, applying the same procedure (function) for all elements except the first one. The simplest example is finding the max ...
ov7a's user avatar
  • 141
5 votes
3 answers
5k views

I have the following class that doesn't implement IEnumerable but is working perfectly with foreach. And also, arrays are working without implementing IEnumerable. So why does it keep saying that ...
Roshan Fernando's user avatar
0 votes
3 answers
126 views

I will use C# here as an example, but my question is about any language. My question is from framework to compiler perspective (i.e the solution can be by implementing given idea inside compiler) ...
greenoldman's user avatar
  • 1,533
7 votes
1 answer
566 views

I am currently writing an API for machine learning algorithms in Rust and I would like for a single genetic algorithm, artificial neural network, or Bayesian network to provide multiple outputs so ...
vadix's user avatar
  • 81
-3 votes
1 answer
5k views

I am implementing an interface I on a class A. Class A implements I. I have an Iterator T that is supposed to return an object which implements I everytime I call next. My iterator goes as follows (...
JOX's user avatar
  • 137
25 votes
6 answers
6k views

I am reading C# Design Pattern Essentials. I'm currently reading about the iterator pattern. I fully understand how to implement, but I don't understand the importance or see a use case. In the book ...
MyDaftQuestions's user avatar
1 vote
1 answer
1k views

Let's say we have a generator that is indefinite, where new elements can arrive at any moment with significant (up to indefinite) delay. An example of such generator is tail -F command. In python (...
Kentzo's user avatar
  • 163
8 votes
1 answer
23k views

I am struggling with making a design choice in the following setup: I am writing (C++) functions which take a pair of iterators (to template containers) and compute a return value of the same type ...
1v0's user avatar
  • 715
-2 votes
1 answer
934 views

By this below definition(pre 1.8) of Iterable, package java.lang; import java.util.Iterator; public interface Iterable<T> { Iterator<T> iterator(); } I would say that, Iterable is ...
overexchange's user avatar
  • 2,325
7 votes
5 answers
10k views

I am writing a library which deals a lot with sub-sequences of ordered containers. So for example I have a container (1,2,3,4,5,6) and a user wants to access (3,4,5). I am providing the subsequence ...
1v0's user avatar
  • 715
8 votes
1 answer
21k views

I often find it cleaner to write a generator than to return a list. For example, I prefer def my_func_gen(foo): for i in foo: # Do some stuff that's too complicated for a list or ...
kuzzooroo's user avatar
  • 615
4 votes
3 answers
7k views

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 ...
Lydia Ralph's user avatar
3 votes
2 answers
2k views

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 ...
Gage's user avatar
  • 131
7 votes
1 answer
2k views

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 perform ...
GlenPeterson's user avatar
4 votes
4 answers
4k views

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: b,...
j--'s user avatar
  • 159
3 votes
1 answer
2k views

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 hood',...
JPtheK9's user avatar
  • 199
0 votes
2 answers
152 views

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 ...
isklenar's user avatar
  • 131
6 votes
0 answers
992 views

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). "...
Paul Klint's user avatar
4 votes
3 answers
539 views

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. ...
Eric's user avatar
  • 375
3 votes
3 answers
7k views

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 ...
Kyle Baran's user avatar