Questions tagged [iterator]

An iterator is an object-oriented programming pattern which for the most part functions similarly to a pointer to an object inside a collection with the added ability to traverse through the collection in a defined manner, agnostic of the actual implementation or even object addresses in physical memory. Iterators may be further limited in particular traversal directions.

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

Iteritems on a slice of a Python list

iteritems on a dict can useful. Occasionally iteritems is useful for a slice of a list and ...
23
votes
5answers
25k views

StreamIterable - create an iterable from a Java 8 Stream

This seems like an easy thing to mess up, so I'd be grateful if you could think of any edge-cases that I've missed. ...
1
vote
1answer
253 views

Homogenising iterator and const_iterator

I've reworked (for C++11) a section of PyCXX which contained an almost identical iterator and const_iterator. I would like to ...
1
vote
2answers
2k views

Double Inclusive Range step by step

I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step. ...
2
votes
1answer
10k views

ArrayList for Shop implementatin

Problem statement: Design a system for the following scenario: An item list contains item code, name, rate, and quantity for several items. Whenever a new item is added in the list ...
2
votes
2answers
368 views

Handling thread interruptions in a directory iterator

This code is code written on a whim to help $someindividual asking for such a thing on $somechatmedium; what is needed is a way, ...
13
votes
2answers
524 views

Elementwise iterator adaptor

There are many C++ implementations of the Euclidean vector. I.e., a vector in what is typically a 3- or 4-dimensional space. Something along the lines of ...
6
votes
3answers
887 views

Cyclic iterator in both directions

I am trying to make a cyclic iterator that works backwards and forwards. getNext() gets the next array item, getPrevious() gets ...
13
votes
2answers
26k views

Self-made linked list iterator

I recently made a linked list for myself, the code of which was posted here, if anyone would be interested. Now, as the next task, I had to make an Iterator for my ...
40
votes
3answers
54k views

Method returning IEnumerable<T> should ToList() or not

I can't decide whether my method that returns an IEnumerable<T> should itself be lazy or whether it should build a list and return that. I often opt for the ...
4
votes
1answer
66 views

Finding the next XML element

I am looking for a better way to do a while cycle with the variable update. The background is that I'm writing a StAX-line XML reader in JavaScript and want to ...
8
votes
2answers
404 views

Array-like container for uints shorter than 8 bits (Rev 1)

This is a follow-up to Array-like container for uints shorter than 8 bits In short: The PackedBitfieldArray should be a kind of container for packed (unsigned) ...
12
votes
1answer
233 views

Array-like container for uints shorter than 8 bits

Follow-up: Array-like container for uints shorter than 8 bits (Rev 1) First of all: yes, I need this kind of array to generate data for a piece of hardware, and it must be stored and manipulated ...
5
votes
1answer
2k views

Optimizing FirstOrDefault

I'm working on an application in which it takes quite a bit of time to initialize the data. Some background: I'm creating a sort of pivot table in which I turn Figure 1 below into Figure 2. I've ...
7
votes
2answers
2k views

Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used)

BEFORE YOU READ: this link should be included when you just don't like the format of the question and for those that read this question for the first time, the link may give you the idea what happened ...
3
votes
1answer
10k views

Compare / Join two object collections LINQ

I have two csv files that I need to compare and merge together. There is a 'big' list with many records and columns of data and a 'small' list of the desired records and some additional data. The ...
5
votes
2answers
103 views

Custom MultiIterator with type filter

I'll start with giving a bit of background as there are many classes involved and I can't attach all of them because that would make this question wildly too long. For the curios they can be found at ...
4
votes
1answer
1k views

Return one particular element first, when iterating a lua table

I wish to iterate through a Lua table, but want to get one particular element first always (its key is known beforehand). Since the pairs function does not guarantee the order of a table's elements, ...
7
votes
1answer
3k views

Python caching generator

Is this the correct way to cache a generator in Python, without iterating over it right away (for example using list() over it)? ...
15
votes
1answer
1k views

CircularListCursor - an efficient circular cursor on any list

I have decided to create my own CircularListCursor, because I wanted some abstraction and a ListIterator<E> couldn't give ...
2
votes
1answer
1k views

Graceful way to iterate through two arrays and build a master array?

params[:controller_id].each do |cid| params[:zone_number].each do |pzn| zone_ids << Zone.find_by_controller_id_and_number(cid,pzn).id end end I have ...
12
votes
1answer
1k views

Custom iterator implementation returning OpenCV Mat

I have written an adapter class that allows iteration over the rows of a Mat object from OpenCV. For those interested, here is the Mat documentation, but the ...
7
votes
3answers
2k views

Iterator of iterator

Given an iterator of iterators, return all of the elements from the iterators in order. Looking for code review, optimizations, and best practices. Verifying complexity to be \$O(n)\$, where \$n\$ is ...
5
votes
3answers
7k views

Iterator for a list of objects

Given a list of objects, return an iterator for such a list. Looking for code-review, optimizations and best practices. Verifying complexity to be O(n) where n is sum of all objects, including ...
8
votes
4answers
23k views

Linked list with iterators

This is my second linked list implementation for review. I rewritten pretty much all of this and have added iterators, sentinels and The Rule of Five. Please let me know what's wrong with it; I am ...
4
votes
1answer
136 views

Container which iterates a range or a list

I have made some composited container Range which accepts either a min/max range as a std::pair or a set of integers as a ...
4
votes
2answers
945 views

Recursive flatten with lazy evaluation iterator

I'm trying to rewrite this: ...
4
votes
5answers
836 views

A deduplicating iterator

Implement an iterator (generic) which skips an element if it is equal to the previous element. e.g: AAABBCCCCD, produces ABCD. Please suggest improvements. ...
45
votes
5answers
170k views

Simple Example of an Iterable and an Iterator in Java

I was a TA for a first-year Java programming course this year. As a very simple example of iterables/iterators, I wrote the following code for the students. I am curious if any styling or other ...
10
votes
2answers
2k views

Using a Pythonesque range() generator function with the Java foreach loop

Now that we have the nice new foreach loop in Java, the old-style loop looks ugly be comparison. I like the way Python has a ...
2
votes
2answers
15k views

Iterator for binary tree - pre, in, and post order iterators

Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc. ...
8
votes
2answers
895 views

Iterator class using a square list

I am trying to implement squarelist by using iteration that points to the head element. I've create this iterator class to make my iterator id directional. I just want to see if I implemented it ...
3
votes
2answers
10k views

Creating linked list data with iterator pattern

I've created a linked list to use it in SquareList. I've started to create a linked list based on just that. I want my class to follow the iterator pattern. How can it be improve to use vector ...
3
votes
1answer
235 views

Serializing tabular data in ruby — is map, flatten, hash the correct approach?

I wanted a hash which lets me reference Japanese syllables by their romanized names. In hindsight I could have searched for an existing one column table, but I wanted to improve my ruby by writing a ...
1
vote
0answers
574 views

REST Response: Checking for Success and Error

I thought this was pretty slick - maybe not, I just wanted to share and maybe get some feedback: As part of a REST client class: Accepts the JSON response from REST or REST-like service, searches ...
11
votes
1answer
2k views

Iterator adaptor for iterators returning tuple-like values

Today, I will require your help to improve an iterator adapter. The goal of the adapter (I called it get_iterator) is to adapt ...
2
votes
1answer
18k views

Nested select Linq

Is there a simpler and optimized way to calculate listAdminCorePriveleges and privileges ? ...
7
votes
1answer
39k views

Iterator Implementation

I had to write my own iterator implementation for my structure which has ArrayList<Vector> field. An iterator is supposed to iterate over mentioned ...
3
votes
3answers
23k views

Check IEnumerable Count

Let's say I have a collection of expensive-to-generate objects stored in an IEnumerable: ...
0
votes
1answer
4k views

Filtering a long list of files through a set of ignore patterns using iterators

I have a backup job that walks across a huge directory with potentially millions of files. Python's os.walk() works just fine. Now, I have implemented a feature to ignore files based in a black list ...
5
votes
3answers
10k views

Flatten iterator for nested list

Given a list which can can contain elements as well as lists, write an iterator to flatten a nested list. Please make this code better and suggest any improvements. ...
3
votes
2answers
244 views

Remove item from a list, which (of the 2) methods is better?

I have a List, and I have to delete one item from the list when I find it. I am using the code below to do that: ...
27
votes
3answers
21k views

“Zip-like” functionality with C++11's range-based for-loop

My goal was to get the following code to work: ...
3
votes
1answer
118 views

copy_if_max() algorithm

I need a copy_if_max() function, i.e. copy all the elements in an input range that are equal to the max in that range. The most obvious implementation does two ...
2
votes
1answer
1k views

Refactor IQueryable and IEnumerable that share the same condition

I have extension methods to encapsulate query conditions, however I have to separate IQueryable and IEnumerable. Is there any ...
2
votes
3answers
1k views

Is this a correct recursive Scala iterator creation?

I am diving into Scala (using 2.10) headfirst and am trying out a simple task of taking bulk data and then doing something with that stream. The first part is generating that stream. I have seem to be ...
3
votes
1answer
3k views

Creating custom random access iterator in C++ 2011

I would like an opinion on my code. I need a random access iterator for my custom container. If I read the C++ 2011 standard, specially chapter 24, I understood that an implementation could be the ...
2
votes
1answer
222 views

How to remove goto statement from iterator

I'm implementing a simple iterator in C# over an xml document, in order to process an xml document in as much a streaming manner as possible. For this reason, I'm using an XmlReader variable in a <...
8
votes
1answer
662 views

Python reversed in C++11

I was playing with some of the wonderful new C++11 features and tried to reimplement a function reversed that would behave just like the one in Python to allow ...
5
votes
3answers
6k views

Most efficient way to iterate through arrays/can I use .times method in place of while method?

I created a quick program to test the precision of randomness generated by the .rand method. The primary question is whether I can use the ...

1
4 5 6
7
8