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
0
votes
1 answer

Make phrases enumerable?

I am writing a package which needs to make some customized phrases (e.g. a bunch of city names) externally accessible. (like a normal enum with name 'MyEnum', when user types in "MyEnum.", all its enumerated members will pop up to let user choose) I…
Ken S
  • 315
  • 1
  • 3
  • 11
-1
votes
1 answer

Is the language L1 = {a^p; p is not a prime number and p>=0} recursively enumerable?

I know the language L2 = {a^m; m >=0} is a regular language, and that L3 = {a^p; p is a prime number} is recursively enumerable. Would L2-L3=L1 also be recursively enumerable and not context free or regular?
-1
votes
2 answers

How to AddRange many lists of IEnumerable> into IEnumerable>

I have those functions public static IEnumerable> GetPermutations(IEnumerable items, int count) { int i = 0; foreach (var item in items) { if (count == 1) yield return…
CDrosos
  • 2,418
  • 4
  • 26
  • 49
-1
votes
1 answer

custom ruby inject method not producing expected output

forgive me I see that this question has been asked in many ways here on forums but none have output the desired output and I have been stuck for a few days reading different explanations of how the inject method works. Could my code be inspected and…
aulbytj
  • 61
  • 8
-1
votes
3 answers

Create Ranges in the list

I have a Price list as 10 21 30 90 100 150 400 I want to add prices in 10 increments below 100. Above 100 to display in increments of 100 So my final price list would be like 10 20 30 40 50 60 70 80 90 100 200 300 400 Has anyone has done…
Owais Ahmed
  • 1,364
  • 1
  • 30
  • 62
-1
votes
1 answer

Accessing the current array inside a ruby method

Is there a way to use the array being acted upon inside of a method, like how in javascript you can send a copy of that array to the callback? so something like: array.something.somethingelse.anotherthing do |element| #i want to be able to…
jjames
  • 93
  • 1
  • 1
  • 7
-1
votes
1 answer

Create deferred enumerable from Func>

Is there a built-in/standard way of creating a deferred IEnumerable, given a Func>? My Google skills may be weak... Suppose I know that some method Foo that returns an IEnumerable executes immediately (and is perhaps…
Andrew
  • 1,494
  • 1
  • 17
  • 27
-1
votes
1 answer

Customized property is not enumerable in Javascript?

I defined my own "Age" type,as part of "Person" type, like this: var Age=function(){ year='1930', month='Jan' } var Person=function(){ name='abc', age=new Age() } var o1=new Person() console.log(o1.propertyIsEnumerable('age')) My…
Troskyvs
  • 7,537
  • 7
  • 47
  • 115
-1
votes
1 answer

Is it possible to pass a value to a YAML list?

I'm looking for a way to pass a value to a list enumerable, so I could produce a set of list items for a
    . The value should be displayed by the item that allows it. new favorites (15)           <-- 15 being the value I want…
Rui Nunes
  • 798
  • 1
  • 8
  • 15
-1
votes
2 answers

C# Ordered enumerable - An object reference is not set to an instance of an object

I have the following code: // OnlineAccountCategory is a class var itemsByCategory = Items.GroupBy(x => x.OnlineAccountCategory); foreach (var items in itemsByCategory) ... Items is a list that contains 1 item. Item has a OnlineAccountCategory…
Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35
-1
votes
2 answers

Enumerable.Zip more than 2 collections?

var productNameTags = document.DocumentNode.SelectNodes(textBox3.Text); var priceTags = document.DocumentNode.SelectNodes(textBox2.Text); var codeNameAndPrice = productNameTags.Zip(priceTags, (n, w) => new {…
TeaAnyOne
  • 477
  • 1
  • 9
  • 16
-1
votes
1 answer

Ruby enumerable take first elements until condition is not met

I built my own class and I made it enumerable and now I want to take as many elements as possible, starting from the first one, so long as let's say the sum of them isn't higher than 10. I'm leaning towards a take_while but I'm not sure how to write…
Robert
  • 178
  • 1
  • 8
-1
votes
1 answer

Trying to write my own all? method in Ruby

There is a method called all? in Enumerable. I'm trying to learn all the methods of Enumberable's library by writing them myself. This is what I've come up so far for the all? method. I sorta understand it but I got stumped when trying to pass…
user273072545345
  • 1,536
  • 2
  • 27
  • 57
-1
votes
2 answers

Iterating over an array of arrays

def compute(ary) return nil unless ary ary.map { |a, b| !b.nil? ? a + b : a } end compute([1,2],[3,4]) Can someone please explain to me how compute adds the inner array's values? To me it seems that calling map on that array of arrays would…
Bo G.
  • 107
  • 2
  • 9
-1
votes
1 answer

How many objects have the same attribute value?

I have an array of objects with top and left attributes like this: [{top: 30, left: 20}, {top:50, left:10}, {..}] I am trying to find how many objects have the approximate same top value. In this case: [{top: 10, left: 20}, {top:10, left:10}, {top:…
StarTrek18
  • 323
  • 4
  • 15