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 ...

learn more… | top users | synonyms (1)

2
votes
1answer
31 views

IEnumerable to typed Dictionary

Scenario A portable controls/widgets library for Xamarin.Forms (PCL Profile 111) contains a combobox/dropdown/picker control where the ItemsSource property is an <...
2
votes
1answer
27 views

Postponed Prime Sequence in Kotlin

Following my previous unbounded prime generator and a followup by Martin R, I've tested the waters in Kotlin by making an unbounded sieve. To quote Martin R's wonderful explanation of the base ...
4
votes
3answers
136 views

Copy range up to delimiter

The problem I was trying to solve sounded pretty basic, but turned out to be a bit hairy. I need to select some lines of arbitrary length from an input stream (file or standard input) and print them ...
3
votes
2answers
59 views

C# enumerable property like .Any that accounts for nulls

Brief Description: A generic extension method that performs the same function as IEnumerable.Any(), but does not throw an error when passed a parameter with a <...
4
votes
2answers
86 views

Enumerating text (ranges) vertically and horizontally

I'm writing a parser and I need to iterate through text vertically (down to bottom) and horizontally (left to right). This alone would be easy but some text parts need to be rescanned by another ...
5
votes
2answers
106 views

Postponed Prime Sieve in Swift

Motivated by Unbounded Sieve of Eratosthenes in Swift, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an ...
3
votes
1answer
42 views

C++ Syncronous Poll Wrapper v2

I recently asked for some feedback on my design for a syncronous wrapper around linux sockets and poll Based on the feedback, I created a new (hopefully more idiomatic) design. socket.h ...
1
vote
1answer
55 views

Phishing Project UserIterator Implementation

As I stated in an answer comment on my previous question, the UserIterator has a much larger footprint than I think most people realize. This question is here to further explain the project, the ...
2
votes
3answers
79 views

QuickSort C++ Implmentation using Iterators #2

This is part 2 of the previous question asked which is at - QuickSort C++ Implementation using Iterators. Based on Jerry Coffin's answer, I have made the changes except for using templates. ...
6
votes
2answers
219 views

QuickSort C++ Implementation using Iterators

I implemented quicksort using iterators. I am will be grateful, if someone can review my piece of code. BTW, I am just selecting the last element as the pivot (which I plan to randomize later) I am ...
4
votes
1answer
98 views

Splicing enumerables together

Basically, what I mean by splice is to take an array of Enumerables, take the 1st element from the first one, then the 1st element from the second one, and so forth, until we come back to the 1st ...
4
votes
2answers
78 views

Python lazy dict with iterator in constructor

This question began as an off-topic answer to this question, but the code here serves a different goal. I wrote the following class for the purpose of populating a dict on demand from an iterator. ...
2
votes
1answer
134 views

IEnumerable and Predicate sets in .NET

GitHub Repository Previously: Countable and uncountable sets in .NET (clean version). Thesis There is a full featured support of countable sets in .NET: ...
2
votes
1answer
47 views

ExtensionMethods for iterating hierarchically data structures depth/breath-first

I wrote a few simple extension methods that allow to traverse a hierachically data structure depth-first or breath-first using LINQ: Usage: ...
3
votes
1answer
72 views

C++11 Quicksort any container

As the title says, simple quicksort to help myself get used to C++ templates and iterators. Main concern is whether there's a better way to template so that you can have a simple function (e.g. ...
3
votes
1answer
67 views

Convert a dictionary of iterables into an iterator of dictionaries

I have a user-editable dictionary of content used to fill in a string.Template and I wanted to allow the user to fill the same template with several values at once. ...
1
vote
0answers
64 views

Scan over parameter iterator for model simulation

I'm writing a small Python application that performs model simulation for many different parameters. The iterator of parameters isn't completely known ahead of time. Rather, the iterator needs to ...
4
votes
1answer
426 views

A Rust iterator to match and replace subsequences

I needed to do transformations on a data stream, not on an element-by-element basis, but on subsequences. This is what I've come up with: https://github.com/peterjoel/rust-iter-replace/blob/master/src/...
3
votes
0answers
123 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
4
votes
2answers
70 views

Standard deviation from iterators

I want this to be similar to the STL algorithms but I don't find it elegant nor concise at all: ...
2
votes
2answers
129 views

Finding a Cartesian product of multiple lists

I came up with an extension method to find a Cartesian product of multiple IEnumerable sets. I was able to achieve lazy enumeration via ...
2
votes
2answers
105 views
2
votes
3answers
219 views

JavaScript Iteration

In my current project I have objects of the following structure: CanvasBundle - Object Some elements... gridCanvas axesCanvas ...
3
votes
2answers
126 views

Custom C++ iterator

So I have written a custom iterator for std::map that allows access to just the "values" of the map and I was wondering if it is the "correct" way to implement <...
4
votes
2answers
101 views

Input iterator in C++

For educational purposes and to understand how iterators are working in C++, I've create an input iterator and I would like others to look at and provide any feedback on my code. ...
2
votes
0answers
45 views

An iterator returning all possible solutions to n-queen problem in Java - follow-up

(See the initial iteration.) Now I have slightly improved performance of the iterator. Whenever we have set a queen at a particular board cell, the previous iteration sacrifices \$\mathcal{O}(n)\$ ...
2
votes
0answers
43 views

An iterator returning all possible solutions to n-queen problem in Java

(See the next iteration.) Given a positive integer \$n\$, I have an iterator that returns all possible solutions to \$n\$-queens problem one by one: QueenIterableV1.java: ...
5
votes
1answer
95 views

Yet another Pythonic range implementation for C++

I recently had the need to loop from zero to some limit only known at runtime. Instead of writing: ...
2
votes
0answers
57 views

Exposing Iterators while Trully Hiding Their Implementation

While implementing classes composed of various collections, I've found that it's pretty hard to completely hide the type of collection used, while still allowing C++ style operations on iterators. ...
8
votes
1answer
148 views

RFC 4180-compliant CSV parser in Java

While looking at a recent question, I realized that there is no CSV parser in the standard Java library. I decided to write one that complies with RFC 4180. Highlights of the standard include: ...
6
votes
1answer
161 views

An iterator returning all possible permutations of a list in Java

I have this class that iterates over all permutations of an input list: PermutationIterable.java: ...
1
vote
2answers
199 views

Combination generator in Java - 2nd iteration

I have refactored the previous combination generator, and now it is an iterator returning combinations as lists. It hides larger constant factors as the previous version, yet it is really easy to use: ...
1
vote
2answers
41 views

multirange iterator

I'm doing some boring math with lot of sums over lot of variables. So, instead of nesting for loops I have decided to use something like this: ...
2
votes
2answers
85 views

Split up an iterable into batches

I was writing a program that had a list of e-mail messages. It needed to group them into batches, with the condition that each batch must have at max 20 messages, and be maximally 50k in size (no ...
8
votes
1answer
98 views

Scala implementation of @rolfl's integer-partitioning algorithm

While reviewing @Martijn's Distinct sums of integers (finding all combinations of positive integers that sum to a given number), I proposed the following solution: ...
9
votes
4answers
987 views

Flags on steroids

What is so bad about [Flags] enum? It does not support IEnumerable<T> anyhow, so to get one we need to use syntax like (...
4
votes
2answers
707 views

Range iterator in ES6 similar to Python and Ruby for

Background and Purpose For those unaccustomed to Ruby, Ruby supports range literals i.e. 1..4 meaning 1, 2, 3, 4 and ...
9
votes
3answers
92 views

Finding if sequential numbers for total exists

Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T Example: ...
10
votes
1answer
132 views

Max element of input iterator range

I came across this SO question on why std::max_element requires a ForwardIterator (as apposed to an ...
8
votes
1answer
104 views

Let's “Iterator” through Fibonacci, forever and ever

Following-up to my previous question, this class is now based on an iterator. The class, instead of forcing the programmer to use up a bunch of memory just to get each progressive number once, they ...
11
votes
1answer
85 views

iterating over the values of a list of ordered dictionaries

I am facing the following problem: I have a special data structure that is a dictionary whose keys are integers (dimensions). The values are also dictionaries whose keys are strings (geometric types) ...
5
votes
0answers
43 views

Using the llvm::iterator_adaptor_base

I'm currently working with the LLVM JIT framework. There is some graph I had to implement for internal cost bench-marking. It has cyclic node dependencies, so I have to use ...
5
votes
2answers
288 views

Mapping & Sorting Randomly Generated Numbers

Below is the assignment I was given and the coding is what I have came up with. I would appreciate criticism on how I did and on ways to have gone differently about it. You want to number your ...
6
votes
2answers
426 views

Random access iterator for custom data type in C++

I am working with an array-like data container through a 3rd party API. So I can not change the container itself to add iterators. There are many different array-like classes, and each have a specific ...
5
votes
1answer
120 views

The final word on contiguous iterators

Following the paradigms of SCARY iterators, there should only be a single iterator-type for contiguous iterators per value-type. Here my code for that iterator, working with C++11+: ...
5
votes
1answer
89 views

Pythonish integer range in Java - follow-up

(See the previous iteration.) I have refactored the Range; now it looks like this: Range.java: ...
12
votes
3answers
1k views

Pythonish integer range in Java

Introduction After getting stuck with a Pythonish integer range in C++, I rewrote the facility in Java. In Python you can say: ...
5
votes
1answer
139 views

Pythonish integer range in C++

Python has that range: >>> range(10, -20, -3) [10, 7, 4, 1, -2, -5, -8, -11, -14, -17] I have this C++ implementation of exactly the same facility: range.h: <...
2
votes
3answers
60 views

Reimplementing enumerate() to produce a sequence or iterator

Apparently it is possible to implement enumerate so it produces a sequence when given a sequence, and produces an iterable otherwise. Sequence can be safely ...
3
votes
2answers
153 views

Singly-linked list implementation with iterators

Taking into account everything you guys told me last time I posted, I came up with this implementation of a singly-linked list, in which the first and last elements are known. I tried to make the ...