Questions tagged [enumerable]

"enumerable" refers to an ordering scheme that enables items in a set, sequence or collection to be readily addressed or traversed.

Enumerable is a Ruby module which can be included in other Ruby classes in order to allow iteration via #map/#collect, #select, #each, and so on.

Enumerable also manifests as the class Enumerator (documentation), which is returned when an iteration method is called without a block (e.g., array.each instead of array.each { |x| puts x }).

Enumerable objects may also utilize chained iteration, e.g., array.each.with_indices instead of array.each_with_indices.

Ruby 2.0 also introduces the concept of lazy enumeration.

In .NET, Enumerable is the class that wraps most common LINQ extension methods.

603 questions
-1
votes
2 answers

Ruby each iterator returning array rather than boolean

I have code like the following (truncated/paraphrased for readability) def board_check? @board.each {|row| check_row_for_truth_conditions(row)} end def check_row_for_truth_conditions(row) return true if row.include("foo") false end Right now…
-1
votes
1 answer

Ruby method call to each using "include Enumerable"

I a trying to follow a tutorial with Ruby, but am getting very confused. Everywhere I find seems to say that defining an instance variable is done like so; class Example def fun # CODE end end e = Example.new e.fun # <- Will run your…
Luke Turner
  • 324
  • 1
  • 4
  • 22
-1
votes
2 answers

Is this a viable implementation of enums in Javascript?

I was interested in a really quick enumeration of constant values for a project I'm working on, but everything I found on StackOverflow was ridiculously over-complicated if all you want is to store several unchanging values in a single place so that…
-2
votes
1 answer

Enum lookup by positioned values using MapStruct

I have implemented my basic requirements, which work well in one simple scenario as mentioned below code snippet. But for new requirements what is the best way out there I need help. New requirement: Statuses in numeric format are used on other…
ravibeli
  • 484
  • 9
  • 30
-2
votes
1 answer

Does Enumerable.AsEnumerable<>() force the evaluation of the expression?

string[] fruits = { "apple", "passionfruit", "banana", "mango", "orange", "blueberry", "grape", "strawberry" }; List lengths = fruits.Select(fruit => fruit.Length).ToList(); Enumerable.ToList() or Enumerable.ToArray()…
Observer
  • 122
  • 6
-2
votes
3 answers

Explicit cast required for Enumerable.Empty

Every example I've read so far (google result/stack question) that expalins the use of "Enumerable.Empty" says that i should be able to use it with an array. The VS compiler however, won't allow me to use it unless i explicitly cast it to the array…
Reahreic
  • 596
  • 2
  • 7
  • 26
-2
votes
1 answer

Why does the ToArray method of the OrderedQueryable class much allocated?

I looked source code of the System.Linq namespace and I noticed that the ToArray method of the OrderedQueryable class created three arrays, but we could use one array for ordering. Why is this done??
Evgeniy Terekhin
  • 596
  • 3
  • 10
-2
votes
1 answer

Enumerable.Last method

I am trying to print the both the value of .First and .Last but only the value of .First() comes up. .Last() just prints my "Text: " word and then blank. I'v tried chainging the i to different values and that just makes the program worse. case 2: …
ziNo
  • 7
  • 2
-2
votes
4 answers

getting a JSON file from a list of Objects in C#

I'm new to C#, so please bear with me :) I have a List of persons like this: List PersonsList = new List(); each Person has three properties: public string Name { get; set; } public string Number{ get; set; } public Adress Adress {…
Amir Shahbabaie
  • 1,352
  • 2
  • 14
  • 33
-2
votes
2 answers

How to group one collection and apply same grouping to other, same-length collections?

I have multiple identical length collections, one timestamp collection of type List and several data collections of type List. The values at each index position in the List
Matt
  • 7,004
  • 11
  • 71
  • 117
-2
votes
1 answer

Fastest way or alternative way of counting elements in a enumerable of custom type in C#

I am doing an except of two DataTables in c#. I've overloaded the IEqualityComparer public bool Equals(T sourceRec, T targetRec) { string srcHash, tgtHash; srcHash = HashGenerator.GenerateHash(sourceRec); tgtHash =…
-2
votes
3 answers

Take 1000 using LINQ

Ok, my linq skills aren't great so im trying to do the following. Say I have 6000 records (email address) I want to add the first 1000 add to bcc, send, take the next 1000 add to bcc, send, take the 1000 add to bcc, send, etc.... Ive started…
D-W
  • 5,201
  • 14
  • 47
  • 74
-3
votes
1 answer

RegEx numeric list

He have a text with a numeric list and he would like a regex for have each items in a array. For give an exemple : text= "Bien sûr, voici trois idées d'articles qui pourraient être intéressants pour votre site : 1. Les impacts des deepfakes sur la…
zeke angel
  • 1
  • 1
  • 1
-3
votes
1 answer

transform single element to Iterable in Java

In C#, I can transform a single element to an IEnumerable<> like this (using an extension method here): static class Extensions { static IEnumerable Yield(this T t) { yield return t; } } I use this when I need to input an…
Kjara
  • 2,504
  • 15
  • 42
-3
votes
1 answer

Understanding `detect` method

I have trouble understanding the detect method in Enumerable. I tried with the sample code: (1..6).detect { |i| i % 2 == 0 and i % 3 == 0 } #=> 6 But I'm still mystified. Any help would be much appreciated.
sulu fiti
  • 1
  • 3
1 2 3
40
41