Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [enumerator]

Enables enumeration of items in a collection.

0
votes
1answer
46 views

Initialisation of Enumerators

So I'm slowly reading my way through a work book and have come to the section on enumerators. During which it gives the example code of public class GameMoves { private IEnumerator _cross; ...
1
vote
2answers
57 views

Instantiation of List with Enumerator

I've seen this line in a code snipped and was wondering of the use of it var item = new List<int>.Enumerator(); What does this do?
2
votes
2answers
80 views

cycle through the rest of Enumerator in Ruby

I have an Enumerator in the middle of some sequence: enum = (1..9).each first = enum.next second = enum.next Now I want to cycle through the rest of the sequence (3..9 numbers). But seeming obvious ...
0
votes
0answers
18 views

Using nested Android @interface - Performance increasement or decreasement?

By now it's known that the use of @interface instead of Enumerators gives a performance increasement due to the reduced consume of memory in runtime. I got into a situation where I have ...
0
votes
4answers
72 views

Replace items in a list — in place

I'm facing an issue with some simple C# code which I would easily fix in C/C++. I guess I'm missing something. I want to do the following (modifying items in a list -- in place): //pseudocode ...
-2
votes
3answers
122 views

Python's enumerate in c++

In Python , instead of colors = ['red', 'green', 'blue', 'yellow'] for i in range(len(colors)): print i, '--->', colors[i] One can write for i, color in enumerate(colors): print i, '---...
3
votes
1answer
52 views

Enumerator's loop magic (No break and no endless loop at the same time)

Good day. Short question How do loop inside a Enumerator.new knows where to stop?. Now more descriptive example. Here are tow snippets of code both of them return same array: [1,2,4,8]. But in ...
1
vote
1answer
41 views

Create iterator from total difference

I want to iterate through the integers from x up to n values further. I can do this for example with: x.upto(x + n - 1) or many other ways, but all of them require me to calculate the end myself, ...
0
votes
1answer
156 views

C# yield return enumerator, continue from part the way through

I am using yield return to process some data, with a non-deterministic set of iterations. I want to start processing, but break from the loop once a condition has been hit (e.g. byte size), pass the ...
1
vote
3answers
207 views

Ruby Split array for two with partition and with_index

Can you give explanation of logic or algorithm of ruby behaviour for this construction: arr = [1,2,3,4,5] arr.partition.with_index{|_,index| index>2} How to formalize logic when iterate through ...
-2
votes
1answer
47 views

How to split array of hashes

I am trying to split an array of hashes. All hashes have the same keys. The expected result would be something that looks like this: 1 = [{"tid" => nil}, {"tid" => nil}, {"tid" => true}] 2 =...
0
votes
2answers
34 views

Ruby Enumerator class

I've read about Enumerator class. And I can't fully understand what's going on here: [0, 1].each { |i| puts i } By itself [0, 1].each returns => #<Enumerator: [0, 1]:each> So the question ...
1
vote
1answer
95 views

GetEnumerator interface implementation

I have this foreach loop where I am trying to go through a documentTables list of Table class which contains Table objects which contain Row class objects. Currently I am getting an error saying : ...
0
votes
0answers
407 views

SSIS - Azure Blob Storage - get list of items stored in blob-container

I need to find out a way to extract list of items or files (e.g.pdfs) stored in blob storage. Then want to upload that list to SQL table. Tried with SSIS 'Foreach Azure Blob Enumerator' to loop ...
1
vote
2answers
75 views

Ruby Enumerator and Enumerable interaction: StopIterator dependency

I have just come across some interesting Enumerator behaviour. There seems to be some dependency in Enumerator on position in an Enumerable - once you have peeked the end of the Enumerable and a ...
-4
votes
1answer
49 views

Can we insure the for loop iteration order when we loop over a list by “for item in list:”? [duplicate]

for a in mylist: print(a) I am wondering whether the item in the for loop iteration will always print the item in order? I know "for i in (len(mylist))" can ensure the order but not sure about ...
0
votes
2answers
34 views

How can I “close” an enumerator in Ruby?

I have an enumerator that loops on data from an external API. The API requests that I notify it when I'm done looping. This is pretty easy when the enumerator is allowed to go until it runs out of ...
1
vote
0answers
649 views

Error - “Your InputStream was neither an OLE2 stream, nor an OOXML stream” while writing to .xls file

In my web application, I was successfully able to export data into an excel sheet using Apache POI 3.14 library and HSSF stylesheets. I had written test cases also for same which included obtaining ...
0
votes
2answers
2k views

Error: Doesn't contain a public definition of GetEnumerator

When I am trying to run the application I am getting this error constantly i.e "CS1579: foreach statement cannot operate on variables of type 'Models.FloorPlanViewModel' because 'Models....
3
votes
2answers
90 views

How are values actually fetched from an Enumerator object in Ruby?

I'm interested in how values are fetched from an Enumerator object. In the following piece of code, I was expecting the first enum.next call to raise an exception as all values had already been ...
4
votes
2answers
115 views

Does enumerator used in expression have the same type as underlying type of its enum?

What is the type of enumeration constant, when it is used outside unscoped enum definition? Consider following code: #include <iostream> enum modes { begin = 0, end = 1 }; int main() ...
1
vote
1answer
104 views

ruby enumerators: immediately skip multiple iterations (or start iterating from n)

I'm iterating over permutations of a list (18 items) like this: List = [item0..item18] # (unpredictable) Permutation_size = 7 Start_at = 200_000_000 for item, i in List.repeated_permutation(...
0
votes
1answer
58 views

How to list files of a folder using contentsOfDirectoryAtURL

I explain my problem: I have some files in my computer, and I want to read them from my iPhone thanks to the Wi-fi (Wi-fi to begin, and after with the 3G network). I opened the WebServer on my ...
2
votes
1answer
98 views

How do get all tasks in

How i can get an iterator for use in Task.WaitAll to wait for all task exist in customList with lowest overhead or lines of code ? public class Custom { public Task task; public ...
3
votes
1answer
98 views

How to understand the work flow in ruby enumerator chain

The code below produces two different results. letters = %w(e d c b a) letters.group_by.each_with_index { |item, index| index % 3 } #=> {0=>["e", "b"], 1=>["d", "a"], 2=>["c"]} letters....
0
votes
1answer
45 views

Strange behaviour -> .GetEnumerator() | .Reset() -> Looking for a way around

I am working with a simple XML file in PowerShell and since I use the GetEnumerator() method I see some strange things when working with my script. When I save something in an object with the ...
0
votes
2answers
47 views

Iterate over all array elements and add a variable to element ruby

I have a CLI App that scraps 5 different deals page and save it into @@all class variable. I want all of them to have a new variable which should start from 1 to 100(because there are total 100 deals)....
2
votes
3answers
156 views

Iterator function for IDisposable items

Suppose I want to create an iterator function that yields IDisposable items. IEnumerable<Disposable> GetItems() { yield return new Disposable(); yield return new Disposable(); } This ...
0
votes
3answers
37 views

C# Error Additional information: The enumeration has already completed

This is my first time using the enumerator interface. I am Trying to look threw a stack to find next occurrence of a string. The loop is suppose to loop threw my tags stack and find out if a tag ...
1
vote
5answers
80 views

Can I manipulate the current iteration of the collection being currently iterated over?

Say I have a collection of @lines, and I want to iterate over it, but I want to manipulate how it is iterated over based on the contents of the collection, how do I do that? i.e. something like this: ...
6
votes
1answer
217 views

Type of an enumerator in the declaration of its enum

In C++, specifically in C++14 n4296, there are two paragraps talking about type of an enumerator, which seem to be contradictory to me. See 7.2/5 (which is 10.2/5 in n4659): Each enumeration ...
1
vote
1answer
58 views

Long version of block passed to map returns Enumerator? [duplicate]

Why does the long version of passing a block to Array#map (#2 below) return an enumerator, while #1 and #3 below return arrays? Method #1: Returns an array result = [1, 2, 3].map do |num| num * 2 ...
0
votes
1answer
10k views

Ruby: undefined method `[]' for nil:NilClass when trying to get Enumerator on an Array of Hashes

I am trying to loop on an Array of Hashes. When I reach the point where I fetch the Enumerator to start looping, I get the following error: undefined method `[]' for nil:NilClass My code looks like ...
1
vote
1answer
330 views

“break” vs “raise StopIteration” in a Ruby Enumerator

If I use Ruby Enumerators to implement a generator and a filter: generator = Enumerator.new do |y| x = 0 loop do y << x x += 1 break if x > CUTOFF end end.lazy filter = ...
3
votes
2answers
623 views

Get annotation value from enum constant

I have an enumerator and a custom annotation that represents the enumerator's description: public @interface Description { String name() default ""; } Enumerator: public enum ...
0
votes
2answers
48 views

Enumerator fails to return the first element

I implemented the IEnumerator interface in my class. It works fine apart from the fact that it never returns the first element in MyListContainer. Only the rest. So to try and fix this I used the ...
1
vote
3answers
105 views

(C#) Enum won't return int

I am writing an application that needs to query multiple databases, so to standardize my connection strings, I wrote the following enum and method: class Program { enum DBEnum { DB1, DB2, DB3, ...
1
vote
1answer
245 views

Generic iteration between collections

So I either have a dictionary or array, and rather than checking null for either and then enumerating through them separately using their own logic i am attempting to find a generic solution that ...
0
votes
2answers
75 views

Ruby peek with include? acts like next

I'm having trouble understanding my own ruby script at the moment. If I check the contents of the next position with peek, intending not to move the position yet, using include?, the position of my ...
0
votes
1answer
72 views

How to cycle array enumeration in Ruby

I want to implement such enumerator that rewinds from last back to first element and continues looping, such an infinite loop. How could it be done?
0
votes
2answers
517 views

Get fullpath or convert to fullpath

When using let directoryEnumerator = FileManager().enumerator(at: ... in Swift 3, I get all files from the folder, e.g. "file:///Volumes/MacOS/fasttemp/Fotos/" The results are not including the ...
0
votes
3answers
80 views

how do I search for a string value inside an array stored in a hash

I am using ruby on rails and trying to figure out if I can (and/or how I) search for a Hash within an Array for a specific string value? If there is a match (finds Bob), I want it to return True. ```...
5
votes
2answers
141 views

Swift equivalent of Ruby's “each_cons”

Ruby Ruby has each_cons that can be used like this class Pair def initialize(left, right) @left = left @right = right end end votes = ["a", "b", "c", "d"] pairs = votes....
0
votes
1answer
54 views

How to close a form after opening another one on top of it

I have the following code - The purpose is that after saving an order, it is has been set to cancelled, then I want it to show the "New Order" form - This works fine! However, once the new form has ...
8
votes
2answers
4k views

`return` in Ruby Array#map

I have a method where I would like to decide what to return within a map function. I am aware that this can be done with assigning a variable, but this is how I though I could do it; def some_method(...
5
votes
2answers
488 views

How can I make a ruby enumerator that does lazy iteration through two other enumerators?

Let's say I have two enumerators, enum1 and enum2 that must be lazily iterated through (because they have side effects). How do I construct a third enumerator enum3 where enum3.each{|x| x} would ...
0
votes
3answers
805 views

C# “Generator” Method

I come from the world of Python and am trying to create a "generator" method in C#. I'm parsing a file in chunks of a specific buffer size, and only want to read and store the next chunk one at a time ...
3
votes
2answers
468 views

Binary search tree IEnumerator.MoveNext() non recursive in order traversal implementation. How to?

After having built a binary search tree BST<Tkey,TValue> which consists of BSTNode<Tkey,TValue> nodes I am trying to implement the IEnumerable interface for it. This is the how I ...
0
votes
2answers
86 views

What does y do in enumerator.new do |y|

I can't wrap my head around it. I tried to consult ruby-doc on enumerator but it did not help much. From ruby-doc: fib = Enumerator.new do |y| a = b = 1 loop do y << a a, b = b, a +...
2
votes
1answer
214 views

Why does each_cons yield arrays instead of multiple values?

I just wanted to apply a binary operation to consecutive elements in an array, e.g.: [1, 2, 3, 4].each_cons(2).map { |a, b| a.quo(b) } #=> [(1/2), (2/3), (3/4)] This is a contrived example, the ...