Questions tagged [enumerators]
24 questions
34
votes
2 answers
What are the pros and cons of Enumerators vs. Conduits vs. Pipes?
I'd like to hear from someone with a deeper understanding than myself what the fundamental differences are between Enumerators, Conduits, and Pipes as well as the key benefits and drawbacks. Some discussion's already ongoing but it'd be nice to have…

Luke Hoersten
- 8,355
- 3
- 21
- 18
22
votes
1 answer
What are C# Iterators and Generators, and how could I utilize them
I am a VB.Net developer, kind of newbie in C#,
While looking in C# documentation I came through Iterators and Generators, could not fully understand the use, I there anyone who can explain (in vb perceptive; if possible)

Rajeev
- 4,571
- 2
- 22
- 35
20
votes
1 answer
Concurrency or Performance Benefits of yield return over returning a list
I was wondering if there is any concurrency (now or future), or performance benefit to using yield return over returning a list. See the following examples
Processing Method
void Page_Load()
{
foreach(var item in GetPostedItems())
…

bendewey
- 39,709
- 13
- 100
- 125
16
votes
3 answers
F# yield! operator - Implementation and possible C# equivalents
I'm currently learning F# and I really love the yield! (yield-bang) operator. Not only for its name but also for what it does of course.
The yield! operator basically allows you to yield all elements of a sequence from a sequence expression. This is…

Johannes Rudolph
- 35,298
- 14
- 114
- 172
11
votes
4 answers
How do Enumerators work in Ruby 1.9.1?
This question is not about how to use Enumerators in Ruby 1.9.1 but rather I am curious how they work. Here is some code:
class Bunk
def initialize
@h = [*1..100]
end
def each
if !block_given?
enum_for(:each)
else
…

horseyguy
- 29,455
- 20
- 103
- 145
10
votes
6 answers
Why doesn't .NET have a bidirectional enumerator?
It's been asked a couple of times on SO how you can implement a bidirectional enumerator (here, here). My question is not how (which is trivial for most cases), but why no such type exists in the .NET platform.
public interface…

JSBձոգչ
- 40,684
- 18
- 101
- 169
9
votes
4 answers
Chaining enumerators that yield multiple arguments
I'm trying to figure out how Ruby handles chaining enumerators that yield multiple arguments. Take a look at this snippet:
a = ['a', 'b', 'c']
a.each_with_index.select{|pr| p pr}
# prints:
# ["a", 0]
# ["b", 1]
# ["c",…

Ben Weissmann
- 137
- 6
4
votes
7 answers
Why does enumerating through a collection throw an exception but looping through its items does not
I was testing out some synchronization constructs and I noticed something that confused me. When I was enumerating through a collection while writing to it at the same time, it threw an exception (this was expected), but when I looped through the…

adeel825
- 5,677
- 12
- 40
- 44
3
votes
1 answer
How does ASP Classic FOR EACH loop work
I would like to now how the ASP Classic/VB6 FOR EACH loop works. I know with .NET IEnumberable/IEnumerator are involved, but how does VB6/ASP Classic do it?
Thanks!

Ian McShane
- 340
- 3
- 10
3
votes
4 answers
Does foreach use IEnumerator/IEnumerable for built-in types?
Does the foreach loop use interfaces IEnumerator and IEnumerable only for iterating the objects of custom types (classes) or also for iterating the built-in types (behind the scenes)?

Prem
- 5,685
- 15
- 52
- 95
2
votes
3 answers
Why ruby's inject doesn't sum correctly?
I'm not getting correct results from the following monkey-patching method in Integer:
def harm
1 + (2..self).inject{|sum, x| sum + 1/x.to_r}
end
2.harm #=> 3
it should return 3/2 instead, where is my mistake?

Ivan Prodanov
- 34,634
- 78
- 176
- 248
2
votes
1 answer
Interleave Enumerators play 2.0
Trying to get my head around Enumerators on play 2.0.4 - I'd like to interleave one Enumerator with another, but only as long as length of the first enumerator (exclusive).
So:
Enumerator("hello", "world") -> "hello" ", " "world"
Enumerator("one",…

barnybug
- 643
- 1
- 5
- 8
2
votes
8 answers
Passing enumerated values to functions
Say I have a function that takes an integer as an argument. I'd like to be able to use an enumerated list as a way to keep the integer values organized.
For example, I'd ideally like to be able to define these (pseudocode):
public enum days
{
…

Gadzooks34
- 1,718
- 2
- 20
- 29
1
vote
2 answers
How can I get the next n number of elements using a Ruby enumerator?
I am trying to get the next n number of elements using a Ruby enumerator, with this:
a = [1, 2, 3, 4, 5, 6]
enum = a.each
enum.next(2) # expecting [1, 2]
enum.next(2) # expecting [3, 4]
But #next does not support that. Is there another way that I…

p.matsinopoulos
- 7,655
- 6
- 44
- 92
1
vote
2 answers
Does changing a item field in a Collection while iterating invalidates the collection?
If do:
foreach(var a in col) {
a.X = 1;
}
Will my iterator over the collection become invalid?
Thanks

Vando
- 179
- 3
- 9