Enables enumeration of items in a collection.
Questions tagged [enumerator]
377 questions
450
votes
1 answer
Scalaz iteratees: "Lifting" `EnumeratorT` to match `IterateeT` for a "bigger" monad
If I have an EnumeratorT and a corresponding IterateeT I can run them together:
val en: EnumeratorT[String, Task] = EnumeratorT.enumList(List("a", "b", "c"))
val it: IterateeT[String, Task, Int] = IterateeT.length
(it &= en).run : Task[Int]
If the…

lmm
- 17,386
- 3
- 26
- 37
50
votes
3 answers
`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(array)
array.map do |x|
if x > 10
…

Automatico
- 12,420
- 9
- 82
- 110
43
votes
6 answers
How can a formcollection be enumerated in ASP.NET MVC?
How can I enumerate through all the key/values of
a FormCollection (system.web.mvc) in ASP.NET MVC?

mrblah
- 99,669
- 140
- 310
- 420
43
votes
8 answers
escaping the .each { } iteration early in Ruby
code:
c = 0
items.each { |i|
puts i.to_s
# if c > 9 escape the each iteration early - and do not repeat
c++
}
I want to grab the first 10 items then leave the "each" loop.
What do I replace the commented line with?…

BuddyJoe
- 69,735
- 114
- 291
- 466
35
votes
2 answers
Strange behavior of Enumerator.MoveNext()
Could someone explain why this code is running in infinity loop? Why MoveNext() return true always?
var x = new { TempList = new List { 1, 3, 6, 9 }.GetEnumerator() };
while (x.TempList.MoveNext())
{
Console.WriteLine("Hello World");
}

ivamax9
- 2,601
- 24
- 33
26
votes
4 answers
C# Foreach statement does not contain public definition for GetEnumerator
I'm having a problem with a Windows Form application I'm building in C#. The error is stating "foreach statement cannot operate on variables of type 'CarBootSale.CarBootSaleList' because 'CarBootSale.CarBootSaleList' does not contain a public…

Danny
- 601
- 2
- 9
- 11
24
votes
2 answers
Why do C# Arrays use a reference type for Enumeration, but List uses a mutable struct?
From what I've read, a design decision was made for certain Collections's Enumerator Types to be mutable structs instead of reference types for performance reasons. List.Enumerator is the most well known.
I was investigating some old code that used…

Chuu
- 4,301
- 2
- 28
- 54
20
votes
1 answer
Comparison of enumerator vs. iteratee package
Currently, there two popular choices which implement the iteratee pattern:
The enumerator package and
the iteratee package.
What are their relative benefits? Is one better than the other, or does it depend on the use-case (and if so, what are the…

hvr
- 7,775
- 3
- 33
- 47
20
votes
3 answers
Ruby generators vs Python generators
I've been researching the similarities/differences between Ruby and Python generators (known as Enumerators in Ruby), and so far as i can tell they're pretty much equivalent.
However one difference i've noticed is that Python Generators support a…

horseyguy
- 29,455
- 20
- 103
- 145
20
votes
2 answers
Returning Multiple Values From Map
Is there a way to do:
a = b.map{ |e| #return multiple elements to be added to a }
Where rather than returning a single object for each iteration to be added to a, multiple objects can be returned.
I'm currently achieving this with:
a = []
b.map{…

Undistraction
- 42,754
- 56
- 195
- 331
19
votes
5 answers
Why is there no ReverseEnumerator in C#?
Does anyone know if there was a specific reason or design decision to not include a reverse enumerator in C#? It would be so nice if there was an equivalent to the C++ reverse_iterator just like Enumerator is the equivalent of the C++ iterator.…

Rado
- 8,634
- 7
- 31
- 44
18
votes
1 answer
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 the following:
def extraireAttributs…

Joe Toug
- 183
- 1
- 1
- 5
17
votes
6 answers
List.All(e => e.MoveNext()) doesn't move my enumerators on
I'm trying to track down a bug in our code. I've boiled it down to the snippet below. In the example below I have a grid of ints (a list of rows), but I want to find the indexes of the columns that have a 1. The implementation of this is to create…

Jonny
- 2,509
- 23
- 42
16
votes
7 answers
Is there a lazy `String.Split` in C#
All string.Split methods seems to return an array of strings (string[]).
I'm wondering if there is a lazy variant that returns an IEnumerable such that one for large strings (or an infinite length IEnumerable), when one is only…

Willem Van Onsem
- 443,496
- 30
- 428
- 555
15
votes
2 answers
Best way to convert a non-generic collection to generic collection
What is the best way to convert a non-generic collection to a generic collection? Is there a way to LINQ it?
I have the following code.
public class NonGenericCollection:CollectionBase
{
public void Add(TestClass a)
{
List.Add(a);
…

J.W.
- 17,991
- 7
- 43
- 76