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
0 votes
0 answers
33 views

Filter by all properties in an IEnumerable<object> using LINQ [closed]

I've made this code to be able to filter an IEnumerable for every object property but I want to know if there is any way to improve this code. ...
user avatar
11 votes
3 answers
794 views

Matrix implementation

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. ...
user avatar
3 votes
0 answers
58 views

A prime iterator in JavaScript

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 ...
user avatar
  • 236
1 vote
2 answers
68 views

Find longest palindrome in a string (LeetCode problem 5)

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. ...
user avatar
0 votes
0 answers
22 views

Get Unique Version of (Async) JS Generator/Iterator

I have a function generatorCreator that returns a generator, here an AsyncGenerator (sync/async should not matter). My purpose ...
user avatar
  • 101
11 votes
4 answers
3k views

Zipping two lists with an offset in Python

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 ...
user avatar
  • 113
0 votes
1 answer
56 views

Action on each element of an inline list

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 ...
user avatar
2 votes
0 answers
150 views

2d Grid - Iterating by Rows / Cells - Take #3

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 ...
user avatar
3 votes
2 answers
162 views

Prime numbers iterator

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 ...
user avatar
  • 933
2 votes
2 answers
110 views

2d Grid - Iterating by Rows / Cells - Take #2

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 ...
user avatar
7 votes
1 answer
200 views

Custom implementation to provide an immutable range of a container without copying it

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 ...
user avatar
2 votes
1 answer
73 views

2d Grid - Iterating by Rows / Cells

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. ...
user avatar
4 votes
2 answers
666 views

Custom implementation to provide an immutable range of a vector without copying it

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. ...
user avatar
3 votes
1 answer
56 views

A counting loop class v2

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 ...
user avatar
0 votes
1 answer
58 views

A simple counting loop class

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-...
user avatar
2 votes
4 answers
305 views

Single-linked-list in C++ with iterators

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. ...
user avatar
0 votes
0 answers
50 views

Binary Tree DFS and BFS traversalsclass [python3]

There are six Binary Tree DFS traversals (preorder, inorder, postorder, and their reverse counterparts). Their implementations can be very similar 1, so I factored out the core logic into a class <...
user avatar
  • 243
6 votes
6 answers
2k views

Left Shift/ Right Shift an array in C

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 ...
user avatar
  • 71
2 votes
2 answers
102 views

Radio with channels

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 ...
user avatar
0 votes
0 answers
20 views

Library To Help Looping Redesign [duplicate]

I have changed the design of my library to help looping with generators. The new version uses iterables which allow a data structure or generator to be passed to the functions. The iterators are then ...
user avatar
3 votes
1 answer
73 views

Using the Decoder class in a streaming context

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 ...
user avatar
  • 1,840
4 votes
2 answers
89 views

Python's enumerate for C++

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 ...
user avatar
4 votes
1 answer
256 views

Iterate through non-empty words from text files

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 ...
user avatar
6 votes
4 answers
300 views

Bidirectional iterate over list in Python

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. ...
user avatar
  • 79
0 votes
1 answer
84 views

Iterating 2d array

I have implemented a MatrixIt class to traverse a 2D array. Is it possible to make the code clearer and shorter? ...
user avatar
-1 votes
1 answer
224 views

Scraping odds portal with beautiful soup

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 ...
user avatar
  • 169
2 votes
1 answer
61 views

Compare strings to markup commentary in main text

...
user avatar
  • 321
2 votes
1 answer
80 views

Adding iterators to C++ sqlite wrapper class

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 ...
user avatar
  • 2,227
3 votes
1 answer
113 views

Image (Const) Iterator using C++17

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 ...
user avatar
2 votes
1 answer
130 views

Implement a range behaviour in Python using iterators

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

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
user avatar
  • 121
1 vote
2 answers
120 views

Racing promises and consuming them in the order of their resolution time

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 ...
user avatar
  • 777
3 votes
3 answers
408 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
user avatar
2 votes
0 answers
90 views

A C++ iterator that adds an extra layer of indirection

This iterator is designed with one purpose in mind. If before you had an iterator where you could do int x = *it; now you do ...
user avatar
3 votes
1 answer
420 views

Forward List Implementation

NB: There's a bug with my iterator, apparently. I can't use const_iterator because I get some compiler errors. I know using const...
user avatar
1 vote
1 answer
153 views

How to optimize this majority vote method

I have the following code to do a majority vote for data in a dataframe: ...
user avatar
0 votes
1 answer
321 views

Random Access Iterator Implementation

(This is the Non-const version, I have to implement the const one too). Could someone please review this implementation? This is made for std::vector I'm unsure whether I respected all requirements ...
user avatar
2 votes
3 answers
2k views

Input Iterator implementation

I need some review on my implementation of input iterator. I am currently re-implementing std::vector, and need input_iterator for a specific constructor. Any criticism is much appreciated! Thank you. ...
user avatar
3 votes
1 answer
99 views

Cyclic generator with access to current local state and executes callback after each cycle

I'm working on a Python class that is a cyclic generator, like itertools.cycle, but it offers access to its current state and executes a callback after the ...
user avatar
4 votes
1 answer
273 views

wrapper class for random access iterator to hide template method implementation from header file

I have a set of template functions that have itrator types as template parameters, so can be used with any kind of iterators. std::find can be a good example. Also ...
user avatar
3 votes
1 answer
123 views

Const wrapper for iterator

Edit: added clarification for why I want this, and updated the code since I don't have any answers yet I have a C++11 array-like class which (can be) a wrapper around a random-access iterator. Index-...
user avatar
  • 131
6 votes
3 answers
683 views

Shorten dict comprehension with repeated operation

dc = {line.split('=')[0]: line.split('=')[1] for line in txt} Below avoids duplication but is even longer: ...
user avatar
4 votes
2 answers
4k views

Convert array of u32 to Vec<u8> in Rust

In Rust, I want to take an array of u32 values, convert each to four bytes in big endian, and concatenate them to yield a ...
user avatar
  • 665
7 votes
3 answers
1k views

Counting words from stored .md files

The following searches recursively for all the mark down files - i. ending with the extension .md - inside a folder. It then stores the text of the files in an ...
user avatar
  • 565
3 votes
1 answer
58 views

Get all routes that start with rt_

The code reads all my routes and return to my AJAX request the names of the routes without duplicates and just those that have the "rt_" prefix. ...
user avatar
3 votes
1 answer
171 views

Rust shortest way to find the maximum product of a fixed length substring

I'm trying to code in a Rust a function, that gives the maximum product of adjacent digits. So given the string 123456789, with 3 adjacent digits, the maximum is <...
user avatar
  • 219
8 votes
1 answer
153 views

base64 iterators

Was a tiny bit bored reading authentication protocols. Needed to clear the mind and read some base64 encode text. So I implemented these iterators that will encode or decode base64 text. Not sure ...
user avatar
  • 91.5k
2 votes
0 answers
131 views

Async linked list to and from async iterable

I'm working on some stuff that works better with (immutable async) linked lists such as this: ...
user avatar
  • 645
3 votes
1 answer
182 views

Extending method chaining IEnumerable with Add..If

I'm trying to write an extension (method chaining) for playing around a bit. What I made work is an extension to add an item to the list (what is pretty easy): ...
user avatar
2 votes
1 answer
105 views

Generate binary image using coordinate vectors

I have a matrix M of size [n_rows, n_cols] and a list of x and ...
user avatar
  • 1,003

1
2 3 4 5
9