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
1answer
50 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 ...
4
votes
2answers
67 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 ...
4
votes
1answer
237 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 ...
6
votes
4answers
194 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. ...
0
votes
1answer
52 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? ...
-1
votes
1answer
101 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 ...
2
votes
1answer
54 views

Compare strings to markup commentary in main text

...
2
votes
1answer
39 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 ...
3
votes
1answer
94 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 ...
2
votes
1answer
50 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 ...
2
votes
0answers
53 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
1
vote
2answers
102 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 ...
3
votes
3answers
180 views

Throttled execution of an enumeration of Tasks

Example of use: var users = await usernames.SelectTaskResults(GetUserDetails, 4); where GetUserDetails(string username) is a ...
2
votes
0answers
74 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 ...
4
votes
1answer
129 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...
1
vote
1answer
69 views

How to optimize this majority vote method

I have the following code to do a majority vote for data in a dataframe: ...
0
votes
1answer
86 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 ...
3
votes
3answers
863 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. ...
3
votes
1answer
74 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 ...
4
votes
1answer
148 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 ...
4
votes
1answer
91 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-...
6
votes
3answers
668 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: ...
4
votes
2answers
1k 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 ...
6
votes
3answers
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 ...
3
votes
1answer
56 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. ...
3
votes
1answer
167 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 <...
8
votes
1answer
116 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 ...
2
votes
0answers
84 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: ...
3
votes
1answer
101 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): ...
2
votes
1answer
93 views

Generate binary image using coordinate vectors

I have a matrix M of size [n_rows, n_cols] and a list of x and ...
4
votes
0answers
357 views

Deep map, Python

Goal: apply fn to every element of an arbitrarily nested iterable (tuple, list, dict, np.ndarray), including to iterables. Ex: ...
3
votes
2answers
112 views

Deep len, Python

Goal: find total number of elements in a nested iterable of arbitrary depth. My shot: ...
2
votes
2answers
136 views

Fibonacci iterator

I've implemented the following Fibonacci iterator: lib.rs ...
0
votes
1answer
57 views

Ensure queue is in ascending order

The program reads in a queue of integers and returns determines whether or not it is valid (ascending). How can this code be improved? I assume iterator include statement is unnecessary? ...
2
votes
1answer
52 views

Iterator-Pattern for an iterator that returns one objects that changes

I wrote an algorithm that returns all k-sized subgraphs of another given graph. Because I don't want to make the runtime of the next() call of the iterator depended on k, I don't want to return a new ...
1
vote
4answers
824 views

Exercise: Design a Stack

Exercise: Design a Stack A Stack is a data structure for storing a list of elements in a LIFO (last in, first out) fashion. Design a class called Stack with three methods. ...
5
votes
1answer
186 views

`zip` operator to iterate on multiple container in a sign

I worked out a zip operator similar to Python's, because I didn't find one in std. It allows to use range-based ...
2
votes
1answer
81 views

template iterable numeric range class with multiple min/max inclusion modes

Problem my code solves: Lack of lightweight numeric range classes which can tell if arbitrary values lie inside them, supporting more than just simple exclusive max modes and integers, and that ...
3
votes
1answer
83 views

Splits up two comma separated items, if they exist

This method splits up two comma separated items, if they exist, and increments the amount if the are already in the list; otherwise add the item to the list I want to know if this code can be ...
2
votes
1answer
70 views

Compare length of iterator with as few `next` calls as possible. How can I deduplicate this code?

I'm writing a few simple functions that compare the length of an iterator to an integer, returning as early as possible. Right now I have: ...
0
votes
1answer
46 views

c# QuadTree yielding properly [closed]

I have implemented a QuadTree of my own, and I'm afraid I didn't use yield properly when I query my tree, my fear is that I create O(HN) iterators. Could you direct me how to better improve the ...
3
votes
0answers
50 views

Populate a list with combinations of one- and two- object functions

I have a nested set of for loops which achieves the desired outcome, but I don't know if it is the most efficient / pythonic way of populating this list. I would ...
9
votes
2answers
628 views

Manipulating list values in python

I wrote a function that I use to preprocess pandas dataframes before running them through a machine learning model. The function works perfectly, however I don't think it's the most pythonic way to ...
4
votes
1answer
91 views

Summation Over Lines in a File (Advent of Code 2018 Day 1)

Preface: I am learning Rust through the Advent of Code The task is to read lines from a file, parse each as an integer, then provide a summation of all the numbers. My solution looks like this: <...
3
votes
1answer
208 views

Iterate through Expression Tree

I'm trying to build an iterator (enumerator) that can select specific elements in an Expression tree by traversing the tree and deferring further iteration until ...
8
votes
2answers
4k views

C++17 zip iterator compatible with std::sort

Here are ~100 lines of code implementing three classes (ZipRef, ZipIter, Zip) which should ...
10
votes
2answers
1k views

Iterator for traversing a tree [v2]

this is an update of the implementation after I followed the feedback from Iterator for traversing a tree. After that I did changed quite a bit on the design and decided to ask for another round of ...
3
votes
1answer
105 views

Iterator for traversing a tree

What I want to achieve is the following: ...
4
votes
1answer
145 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
1
vote
1answer
33 views

Bidirectional numeric (floating point) sequence iterator

I wanted a neat iterator that will always give me neat sequence of step spaced numbers. This is what I came up with, but I am a bit skeptical that I covered all ...

1
2 3 4 5
9