Skip to main content

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
1 vote
0 answers
56 views

(See the previous iteration here.) This time, I have incorporated the answer from YawarRaza7349. Now, my code looks like this: ...
coderodde's user avatar
  • 32.3k
3 votes
3 answers
228 views

(See the next iteration here.) (See the previous iteration here.) This time, I have incorporated a nice answer from Simon Forsberg. Now, my code looks like this: ...
coderodde's user avatar
  • 32.3k
1 vote
1 answer
66 views

(See the previous iteration here.) (See the next iteration here.) This time, I improved the iterator such that there is no chance of numeric overflow when computing the total number of iterations. To ...
coderodde's user avatar
  • 32.3k
4 votes
1 answer
91 views

(See the next iteration here.) Intro This time, I have an Iterator<List<Integer>> implementation that generates list index tuples in lexicographic order....
coderodde's user avatar
  • 32.3k
6 votes
2 answers
84 views

In different code bases I regularly encounter tree data structures of different design and usually need to traverse it at some point. I finally got tired of writing yet another iterative traversal by ...
besc's user avatar
  • 163
3 votes
1 answer
137 views

I have an object graph which contains two types of objects that I care about: Link objects that contain an ID and a reference to the object with that ID. ...
ScottishTapWater's user avatar
5 votes
1 answer
182 views

I am trying to implement an odometer in Rust. This should a be an iterator that yields items of type [u16; N] and it should be generic over const ...
RBF06's user avatar
  • 153
2 votes
3 answers
146 views

I wrote a Vector (dynamic array) class with an iterator usable with std::sort() . It seems to pass my tests. I wondering about the issues one can spot on this ...
KcFnMi's user avatar
  • 139
3 votes
0 answers
502 views

After spending a considerable amount of time poking at the internals of the Collection class, I have discovered 2 methods to iterate a private internal array within ...
Cristian Buse's user avatar
1 vote
1 answer
405 views

I read data from Excel into a Pandas DataFrame, so that every column represents a different variable, and every row represents a different sample. I made the function below to identify potential ...
Pimsel's user avatar
  • 25
4 votes
3 answers
193 views

I'm learning Rust by solving ProjectEuler problems. To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
Bram's user avatar
  • 93
0 votes
1 answer
123 views

I want to extend generic iterators with a convenience function until() that works like an inversion of take_while(). Here is the ...
user avatar
4 votes
2 answers
202 views

The tricky thing was keeping copies of list iterators in a tree map and managing both together. I'm not handling invalid input cases (like popping an empty stack) in this code. I am following Google C+...
user267704's user avatar
3 votes
2 answers
975 views

I have this Python Package called ToTemp under development for precise Temperature Conversions and currently thinking in changing the method's implementation to be ...
eddyxide's user avatar
  • 141
4 votes
2 answers
578 views

I wanted to play with a two-dimensional generic data container in C++ and explore different methods of traversals: using closures and iterators. I'd like a review of it. ...
nowox's user avatar
  • 1,121
2 votes
1 answer
278 views

Yesterday, inspired by some great questions here, I decided to give myself some practice with Rust, by solving all the introductory questions over on LeetCode. It was a great learning exercise, and ...
Davislor's user avatar
  • 9,175
3 votes
1 answer
193 views

I'm preparing for the Advent of Code 2022, and in order to shake off the cobwebs, I'm attempting some problems from the previous year in rust. Starting at Day 1, I've been trying to get comfortable ...
C.Nivs's user avatar
  • 3,117
4 votes
0 answers
181 views

I've finally come up with working solution for day 12 of AdventOfCode, where you have to find the number of possible paths in a cave system following a given set of rules (described below). My ...
Oleg Shevchenko's user avatar
1 vote
1 answer
108 views

I'm trying to build a function to return an Iterator with no duplicated float values, its working, but there is a better way of handling this duplicated values? ...
eddyxide's user avatar
  • 141
3 votes
0 answers
200 views

This work is motivated by Sum of natural numbers below threshold, where several Swift solutions to Project Euler #1 (with arbitrary upper bound) are provided. One way to think of it is to start with ...
Martin R's user avatar
  • 24.2k
2 votes
0 answers
132 views

This post is about an Iterator iterating over simple loops of an undirected graph. In the above graph, the cycle \$\langle 1, 2, 3, 4, 5, 3, 1 \rangle\$ is not ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
145 views

Recently, I needed to sort iterators by their first value and/or use them in BinaryHeap. There are things I don't like about this implementation: Using RefCell. ...
night-crawler's user avatar
12 votes
4 answers
2k views

I am trying to implement an optimal and fast running matrix in C++. I need some review of the code and ideas on how to improve the code quality if it shall be. ...
Hrant Nurijanyan's user avatar
3 votes
0 answers
94 views

This is an implementation of a Sieve of Eratosthenes as [Symbol.iterator] in JavaScript. Comments welcome, my JS is a bit rusty. Making a class of this is mainly the reason to have fun with the ...
thst's user avatar
  • 236
1 vote
2 answers
197 views

The code below is my solution to the following problem (problem #5 on LeetCode): Given a string s, return the longest palindromic substring in s. I wonder whether my use of iterators is an overkill. ...
AlwaysLearning's user avatar
12 votes
4 answers
5k views

Walking my first steps in Python from C, I find myself missing pointers from time to time. In this case I want to go through a list processing two element at a time, where those elements are step ...
xcaliph's user avatar
  • 123
0 votes
1 answer
282 views

I'm trying to learn the "functional" part of C#/.Net for work, and I'm not sure if this is a good way to write this statement. I was also trying to reduce duplicated code while not ...
Classiest's user avatar
2 votes
0 answers
254 views

Edited with a bit more unit tests. Preface Following my second version: 2d Grid - Iterating by Rows / Cells - Take #2 I believe that I am now satisfied with this new version below. There is still one ...
Shigoto Shoujin's user avatar
3 votes
2 answers
452 views

I am not familiar with iterators. I am confused with the traits approach and the traditional one. I don't know which one I should use in 2021. I wrote a minimal ...
nowox's user avatar
  • 1,121
2 votes
2 answers
283 views

Preface Following my first POC version: 2d Grid - Iterating by Rows / Cells I have gained much more understanding, and present A new version A new version is ready, with templates and an attempt at ...
Shigoto Shoujin's user avatar
7 votes
1 answer
390 views

I needed to pass a const reference to part of a std::vector without copy. I posted the previous version in my earlier question, thank you for the great support! As ...
Dávid Tóth's user avatar
3 votes
1 answer
332 views

The feature Here is a Grid class representing a 2d grid. The class will get templated once it reach a satisfactory state. At this time the cells are int values. ...
Shigoto Shoujin's user avatar
4 votes
2 answers
1k views

Edit: A new and improved version can be found in this question, based on the feedback! I needed to pass a const reference to part of a std::vector without copy. ...
Dávid Tóth's user avatar
3 votes
1 answer
104 views

Rewrite of A simple counting loop class based on feedback: This version adds a step parameter and better iterator concept support. Counting is always done in a signed integral, and only integers and ...
Glenn Teitelbaum's user avatar
0 votes
1 answer
107 views

EDIT: Updated version available here: A counting loop class v2 Ranges (C++20) aren't quite ready, so until then, I needed a reliable counting loop class that ​works fairly well to replace the old-...
Glenn Teitelbaum's user avatar
2 votes
4 answers
2k views

I'm implementing a single linked list as close as it could be to std::forward_list. I would welcome a review and also more suggestions on what to test additionally. ...
user3638488's user avatar
6 votes
6 answers
10k views

I am trying to implement a Left shift/ Right Shift on arrays. I was able to accomplish this using double loops. Can the efficiency be improved? This is the working code for LeftShift/RightShift which ...
Vishnu's user avatar
  • 171
2 votes
2 answers
195 views

Realize the Radio and Channel classes that represent radio and a radio station. The radio class offers an argumentless constructor and the following methods: addChannel: stores and returns a new ...
Giuseppe's user avatar
3 votes
1 answer
188 views

Am experimenting with the IAsyncEnumerable interface and PipeReader class. Have come up with the following to decode a stream of bytes into chunks of characters and am able to decode all of my test ...
Kittoes0124's user avatar
  • 1,960
5 votes
2 answers
478 views

I implemented an enumerate() method for C++ containers similar to Python's enumerate to iterate through a range with an index and the actual value. I have the following questions: Does the usage of ...
SourceChris's user avatar
4 votes
1 answer
312 views

Given a file or directory, create an iterator that returns the non-empty words from the file or from all files recursively in the directory. Only process ".txt" files. Words are sequence of ...
Abhijit Sarkar's user avatar
7 votes
4 answers
878 views

I wrote a short function to iterate over a list starting at a given index, then flipping back and forth between left and right values. ...
Antyos's user avatar
  • 189
0 votes
1 answer
327 views

I have implemented a MatrixIt class to traverse a 2D array. Is it possible to make the code clearer and shorter? ...
dankatle's user avatar
1 vote
1 answer
992 views

This code scrapes www.oddsportal.com for all the URLs provided in the code and appends it to a dataframe. I am not very well versed with iterative logic hence I am finding it difficult to improvise on ...
PyNoob's user avatar
  • 199
2 votes
1 answer
127 views

...
Sati's user avatar
  • 427
2 votes
1 answer
266 views

I recently put up my C++ class to wrap the sqlite3 c library here: Thin C++ wrapper for sqlite3 C library One of the suggestions was rather than to specify a vector for arguments to functions instead ...
arcomber's user avatar
  • 2,531
3 votes
1 answer
198 views

I am trying to learn how to correctly implement an iterator (and its corresponding const variant) using a single template, so I would appreciate any criticism to the following code. It's an forward ...
Black Arrow's user avatar
2 votes
1 answer
637 views

I've been assigned the following Python homework: Implement myrange that acts like range using iterators. Define a function ...
bobinthebox's user avatar
3 votes
0 answers
161 views

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
zdebruine's user avatar
  • 153
1 vote
2 answers
609 views

The ideas are When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired. To construct a modern emitter of async ...
Redu's user avatar
  • 946

1
2 3 4 5
9