Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

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
1answer
61 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 ...
12
votes
4answers
5k views

Basic iterator supporting vector implementation

On the fly, I just implemented this iterator supporting vector class to understand how range-based for loop works. It's really basic but let me know what can be improved. Vector.h ...
0
votes
1answer
20 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 ...
5
votes
2answers
129 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
673 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
64 views

Iterator for traversing a tree

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

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
7
votes
1answer
57 views

Apply arbitrary action during recursive generator function

I've got this recursive generator function. It will traverse an object looking for "leafs", any keys that don't point to sub-objects. Then it applies one of two actions on the leaf and yields it. Any ...
6
votes
0answers
74 views

Generating integer partitions

I've tried to implement integer partition algorithm as described in blogpost below (author implemented it in Python): Generating integer partitions I'm still trying to learn best practices in ...
2
votes
0answers
49 views

Combining two nested for loops into one [closed]

Description What this does is it takes a randomly generated 64x64 stack and checks for overlap within the 64x64 array. Here is an example: https://imgur.com/a/kkPRzhn. Each color is its own ...
2
votes
1answer
57 views

A simple priority queue in Java via linked list sorted by priority keys

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
1
vote
1answer
60 views

A GapHelper static class to create unique (non-existing) size restricted names

I am working with a 3th party library which has following interface defined for a processing task: ...
7
votes
1answer
211 views

Map unique raw words to a list of code words

Problem Write a function that replaces the words in raw with the words in code_words such that the first occurrence of each ...
6
votes
0answers
105 views

General algorithm to calculate sums of all subsets of a given sequence of numbers

Background A recent question Print sums of all subsets made its way to the Hot Network Questions list. The problem is simple: Print sums of all subsets of a given set Given an array of ...
2
votes
1answer
44 views

Rendering JSON arrays of unequal length as a table

I have a website where my users can create "table-like" layout dynamically. So imagine that my users can upload a text document, and then append columns to the document, and the output will then be ...
1
vote
1answer
83 views

c++ python like range function to use in for loops

It's a simple range function that works like python range and it is only a syntactic sugar for the usual for loop if we want to operate on numbers in the range from 1 to 10 (1 ... 9) we use this code ...
3
votes
1answer
67 views

Aggregation on list forEach and maps improvals

I am using a function in a SpringBoot @RestController, with Lombok This function is an intermediate result that permit me to do an aggregation between two classes. This 2 classes are: ...
7
votes
3answers
385 views

LINQ Extension methods MinBy and MaxBy

LINQ Extension I present a LINQ method ArgBy that returns the item of a sequence that corresponds to the predicate specified. Two additional methods ...
8
votes
2answers
164 views

Doubly-linked-list implementation in C++

I am fairly new to C++ and have been trying to make a doubly-linked-list class that imitates std::list (though not all of it). I'd appreciate if someone can look at my code and let me know if I have ...
2
votes
2answers
91 views

JS to create Table data dynamically

The following codes generate table row dynamically. I wonder if there are better ways of generating the same data. Also instead of manually coding the heading and the table itself, is it possible to ...
3
votes
2answers
63 views

A basic trivia app

The app grabs 10 questions from an API, displays them one by one with 4 multiple choice answers. These answers are clickable buttons that alert to whether the answer is correct or not. Finally the ...
7
votes
2answers
140 views

Python-style Generator in Java

I have implemented Python-style generators within Java. I might be reinventing the wheel here, but I feel that the ability to define a Generator with an anonymous class is the most flexible approach. ...
1
vote
1answer
95 views

Sorting a list of IComparables

I have a DateTime class (my own, not System.DateTime) which implements the IComparable ...
4
votes
1answer
49 views

Using best practice with complex iteration

I'm new to Rust so I'm still learning how to use best practice in complex examples. Below is some code I've used in one of my programs, a simple implementation of a standard neural network. Here is ...
4
votes
3answers
552 views

LISP-like list class

So, here's my code: ...
3
votes
2answers
55 views

Loading items for an eCommerce site

I am attempting to make an eCommerce site from scratch. Right now I have the following code that gets all the items from a Firebase Firestore database and then adds HTML into an items div based on the ...
1
vote
1answer
60 views

Replace values in R data frame according to values in other data frame

I would like to change row names values from a first data frame if these rows names are present in another data frame, and change it to a corresponding value (defined in the second data frame). I ...
2
votes
1answer
82 views

Add method to Ruby's Enumerable module that produces every nth element

The task is to enhance the Enumerable module with a method nth(). The method shall create a new list, which contains every nth-...
2
votes
1answer
49 views

C++ singly linked list with iterator

I have written a simple singly linked list in C++. I have previously had a data structure in an interview criticised for being too C-like (no iterators and using new/delete) instead of smart pointers. ...
1
vote
1answer
137 views

ShuffleBag (Fisher-Yates + PcgRandom)

Anything that could be done better here? ...
5
votes
2answers
78 views

Filename sequencer with outdated C++

My path to learning C++ has been a rough one. Currently, I'm writing a project and my knowledge is very outdated. While I can write code that accomplishes the tasks required, I'd like to improve and ...
5
votes
2answers
223 views

Lag Lead Enumerator

I had a need to do a look-ahead and look-behind when enumerating though and IEnumerable. Here is a classic situation: ...
2
votes
2answers
53 views

Implementation of enumerate

I'm trying to implement the enumerate built-in using iterators. So far it works but for unordered objects, such as sets or dictionaries, I'm not sure if this implementation is considered valid, ...
5
votes
3answers
249 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
7
votes
3answers
502 views

Generator iterator with push back function

In a compiler project for an LL(1/2) grammar, I have had a need for a generator iterator with a push back function. I have been surprised not to find any perfectly applicable solution (clean, simple, ...
4
votes
1answer
114 views

Email Generator

I've made a email generator, that uses a HTML template and replaces keywords in the template with information taken from a database. I'm looking to see if there is a way to improve the coding. ...
3
votes
1answer
58 views

C function to fully consume a Python iterator

I was reading into the proper way to consume an iterator on this question as well as here and I notices there is no actual proper function for this that clearly explains itself. Using: ...
4
votes
1answer
79 views

Iterable hashtable implementation in C

I'm just finished my version of iterable hashtable. I want to review code in general (code style, data structures, remarks about the algorithms) and I have some questions: I don't know how to ...
3
votes
1answer
91 views

Most efficient way to loop through files using VBA Excel

I have a procedure for looping through all files in folders and subfolders starting at a folder which the user can select. The user can select both the source and target folder. I'm using Excel VBA ...
22
votes
5answers
23k 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. ...
2
votes
2answers
73 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
3
votes
0answers
38 views

Rust Iterator that correlates a slice with itself

In my effort to learn Rust I've tried implementing an Iterator that splits up a buffer in two halves, and correlates both halves by sliding them over each other with different positions (lags). You ...
1
vote
1answer
68 views

Sequence for Pre-order traversal of Binary Trees

I wanted to make a Sequence that can do a pre-order traversal of Binary Tree. Doing so provides automatically unlocks wonderfully useful methods, like ...
5
votes
2answers
77 views

Simple linked list with two iterators

As part of the practice, I created minimalist linked list named SimpleList which can be iterated in two different ways: one element after another or by every second ...
5
votes
4answers
774 views

Take a desired string, iterate through objects to see if it exists in a given field and append a number until a unique string is found

I wanted to in the most generic way possible write a method in C# to achieve the following. Take in a string, a set of objects, and a function to access the field of a given object Look at all of the ...
22
votes
4answers
4k views

Count all vowels in string

For a homework assignemnt, I was asked to complete this CodeStepByStep problem. It's coded correctly and gave me a right answer. I'm just wondering if there's an easier way to solve this problem ...
1
vote
1answer
127 views

Find all starting indices in a string which are anagrams of a word

The task: Given a word W and a string S, find all starting indices in S which are anagrams of W. For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4. My solution: ...
10
votes
2answers
159 views

String sequence in ES6

Given an unique string that represents a sequence of characters, the class should implement three methods (getNextChar, getNextString and the genSequence generator). How it works We give a sequence ...
1
vote
2answers
46 views

Combining arbitrary number of lists inside json

I have some JSON where each key stores an array, and I need to combine all those arrays into a single array. My current solution doesn't seem the most friendly to review, but without ...
2
votes
1answer
162 views

Speed up fast poisson disk sampling generator in Python

I wrote a generator class which implements Fast Poisson Disk Sampling algorithm in Python. I did some optimizations like, x ** 2 -> x * x, using unpacking ...