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
votes
1answer
25 views

iterator that iterates over a file by paragraph [on hold]

I wrote the following iterator to tackle the following problem. I have the following string contained in a file called "example.txt": ...
2
votes
2answers
44 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, ...
4
votes
3answers
175 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
2
votes
0answers
26 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
1answer
105 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
51 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
75 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 ...
1
vote
1answer
31 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 ...
3
votes
1answer
67 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 ...
3
votes
0answers
33 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 ...
2
votes
2answers
59 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
1
vote
1answer
64 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
72 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 ...
20
votes
4answers
3k 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
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
94 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 ...
4
votes
3answers
107 views

Linked list implementation C++

I hope this is the right way of doing things: I've previously posted a request for a code review and gotten feedback. Now I have new improved code that I would like a code review on again. Old: C++ ...
5
votes
2answers
110 views

C++ linked list iterator implementation

I'm a first year computer engineering student and would appreciate feedback on some code. I've created a linked-list with an iterator to be able to range for loops like: ...
3
votes
1answer
60 views

Optimizing quicksort

I created simple quicksort algorithm using iterators. I'm happy with implementation but not with its speed. Profiler tells me that the slowest operation here is ...
1
vote
0answers
51 views

itertools.produce reduced and filtered

I need to generate list of all allowable test combination values of of actor, action and ...
11
votes
3answers
2k views

Decoding assembly instructions in a Game Boy disassembler

I am coding a game boy disassembler in C++. The program (simplified here) converts a vector of byte into an assembly instruction and print it. To do so, it iterates through the vector of bytes (char)...
2
votes
1answer
22 views

Short analogue of Riffle[] accepting two blocks

I have an array of some elements that I need to loop through (i.e. execute some block A on each element) but between them I have also to "clean up" (block ...
1
vote
1answer
42 views

Merging (not removing) duplicated elements in a vector

There's a struct named Player containing name and stat: ...
2
votes
2answers
68 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
3
votes
2answers
83 views

Infinite and countdown counters

I'm refactoring my scheduler and for one of its triggers I need an endless counter that would automatically restart. Since this is a simple and very common task I don't want to ever have to implement ...
4
votes
3answers
86 views

My implementation of a for_each function that traverses a std::container by some step size integer N

As my answer to Iterating over an odd (even) elements only in a range-based loop, I wrote this function, with the following driver program and output: ...
4
votes
1answer
43 views

Rust version of basic functional prime stream - can this be made less clunky?

I'm looking at implementing the basic functional not-quite-Eratosthenes prime stream in Rust. I like to try it when I start learning a language. Here's the bog standard Haskell version: ...
1
vote
1answer
93 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: ...
2
votes
1answer
88 views

Iterating over different Objects which are ordered by index number

I am currently working on a bigger project where I found a part of it which seems very ugly to me from the code. I stripped out the algorithm and made a working code, so it can be reviewed. I have ...
1
vote
1answer
286 views

Applying multiple php FilterIterator instances in a cascading fashion

I wrote an implementation of php FilterIterator objects that allows me to apply them in a "cascade" way, so I can finally obtain an array of objects which is the ...
0
votes
0answers
57 views

An iterator returning all possible permutations of a list in Java - follow-up

(See the previous and initial iteration.) My main attempt here was to get rid of monolithic code and split the implementation into smaller methods when applicable and do more extensive commenting. ...
5
votes
3answers
511 views

Python generator for “barely obtuse” triangles (Project Euler 224)

I am trying to solve Project Euler Problem 224: Let us call an integer sided triangle with sides a ≤ b ≤ c barely obtuse if the sides satisfy a2 + b2 = c2 - 1. How many barely obtuse triangles ...
4
votes
2answers
81 views

Python grouped iterator

I wanted to write an iterator that would split items up into groups, so i can bulk insert into mysql without crashing or overwhelming the server. This is the implementation I came up with. I am ...
2
votes
0answers
40 views

Iterator that groups elements of its source

I wrote an iterator to access the pixel in an packed image. It works, but it is slow. 1.Are there any mistakes that can be avoided and might lead to better speed? 2.Are there any pitfalls that ...
2
votes
1answer
51 views

Class representing digital PLC address

I have a project where I work with digital addresses for a Programmable Logic Controller (PLC). The requirement is that the user gives a start address e.g. 1000.0 and then for example the next 20 ...
4
votes
2answers
109 views

Finding the common iterator category in C++

I created a template trait which finds the common iterator category between a set of given iterator categories. More specifically, it's a class with a member type alias to one of the iterator tags ...
2
votes
1answer
35 views

Finding the Original Fractions from Rounded Decimals

The data I'm using is summoning rates from a gacha game, One Piece Treasure Cruise. The game provides the probability of getting a certain character in percents rounded to the nearest thousandth. ...
6
votes
2answers
144 views

Walking directory tree like python does

I like python's os.walk and I was missing it in C#. It's a very convenient API so I thought I create my own utility that does something similar. The original API ...
4
votes
1answer
261 views

back_inserter for several container arguments

Recently I wrote a back_inserter with the same interface as the std::back_inserter just for supporting several containers in the constructor and doing push_back for each. The solution needs C++17. ...
1
vote
1answer
68 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
-1
votes
1answer
75 views

Check if an element exists in a list of dictionaries [closed]

The logic of the code to build was as follows, two logical conditions; If the value of dictionary element matches in the list of dictionaries return the particular dictionary, and if no element ...
4
votes
1answer
1k views

Reverse C++11 range-based for loop

I wrote this snippet: ...
0
votes
0answers
49 views

Deferred Iteration in TypeScript

I've published a new TypeScript library currently in beta, and was hoping to get feedback on certain aspects of it, particularly implementation details for improving the performance of deferred ...
6
votes
1answer
59 views

General nested for

I needed a general-purpose function that accepts some sequence_container<sequence_container<T>> and iterates all permutations of the inner container. To ...
6
votes
3answers
171 views

Progress bar wrapper class in C++

I've recently written a simple progress bar class in C++ to mimic usage of similar libraries I've used in Python. The idea is to take some iterable container (e.g. ...
5
votes
4answers
770 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 ...
2
votes
1answer
115 views

Handling related generic type parameters

In answering a question on StackOverflow, it occurred to me that a more generic version of GroupBy for C# that delegated membership in each group to a class could ...
-1
votes
1answer
347 views

putting sql-query response directly to foreach-loop?

Is there any reason to not do this? Putting the query directly inside a foreach-statment when the only time the result is going to be used is within that location.. ...
10
votes
4answers
3k 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 ...
7
votes
3answers
143 views

Endless stream: stream a range and return default value if the range is exhausted

Introduction: Motivation Sometimes there is a need to merge N > 1 ranges, and they don't have equal length, but there is a value which can be used in case the range is already exhausted. It is ...