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
3 answers

Populate new_hash where the unique values from old_hash are the keys, and the keys from old_hash are values, grouped into arrays.

I am new to programing and am starting with Ruby. Using .each ONLY, my challenge is to turn this: animals = { 'leopard' => 1, 'gorilla' => 3, 'hippo' => 4, 'zebra' => 1, 'lion' => 2, 'eagle' => 3, 'ostrich' =>…
NickTerrafranca
  • 109
  • 1
  • 8
0
votes
3 answers

Find item in Enumerable with the maximum property value

I'm writing an entry for an AI competition in C#, and I'm looking for a more elegant way to search for items. (I'm much more familiar with embedded C programming, but I prefer C# for an AI contest.) The contest server is using dmcs to compile…
0
votes
4 answers

Find set of objects in array that have same attributes

Given that I have an array with two attributes: 'n_parents' and 'class', which looks like this: my_arr = [{n_parents: 10, class: 'right'}, {n_parents: 10, class: 'right'}, {n_parents: 5, class: 'left'}, {n_parents: 2, class: 'center'}, {n_parents:…
StarTrek18
  • 323
  • 4
  • 15
0
votes
2 answers

Need to know the working of this code which uses AsEnumerable

When I run this code: return dbAccess.ExecuteDataTable(dbAccess) .AsEnumerable() .Select(r => r.Field("Id")) .ToList(); It gives me an error: SqlParameter is already in the…
Lakshay Dulani
  • 1,710
  • 2
  • 18
  • 45
0
votes
2 answers

Quickest way to obtain a repetitive query string

I need to use the following string as part of my query: "(lower(first_name) LIKE lower(:first_param) AND lower(last_name) LIKE lower(:second_param)) OR (lower(first_name) LIKE lower(:second_param) AND lower(last_name) LIKE lower(:first_param))" And…
Jacka
  • 2,270
  • 4
  • 27
  • 34
0
votes
1 answer

ruby facets map is to every as find is to?

the every method is defined as ... def every per(:map) end ... does facets define a method for ... # name not relevant def find_where per(:find) # or :detect end ... I've checked the documentation, most likely I'm just missing it
jtzero
  • 2,204
  • 2
  • 25
  • 44
0
votes
4 answers

Ruby equivalent of Python's list() for enumerables

In Python, we can use the list() method on an enumerable to create an ordered list based on the enumerator's items. How would you accomplish this in a Ruby enumerable? This is currently what I'm using, but it feels a bit hack-ish: data = [] e = # ..…
beakr
  • 5,709
  • 11
  • 42
  • 66
0
votes
2 answers

How to apply a block passed to each element of an array

I have an array of arrays, and I was wondering how I can call a block (if passed) to each of the elements of the array. E.g.: [[1,2],[3,4],[5,6]].custom_method(first_par,second_par) {|element| p 'This is:' + element.inspect}
mathinvalidnik
  • 1,566
  • 10
  • 35
  • 57
0
votes
3 answers

Class that contains a list of objects

I have this class to hold the properties of my data returned from my database call public class Equipment { public string EquipmentId { get; set; } public string Description { get; set; } public string Model { get; set; } public…
user2146538
  • 334
  • 1
  • 5
  • 23
0
votes
5 answers

What is an idiomatic way to update hash keys in Ruby?

When iterating though a hash, keys cannot be changed. Suppose you want to add '_new' to each key: hash = { 'a' => 1, 'b' => 2 } new_pairs = Hash.new hash.each do | k,v | new_pairs[ k + '_new' ] = v hash.delete k end hash.merge! new_pairs Is…
B Seven
  • 44,484
  • 66
  • 240
  • 385
0
votes
1 answer

jQuery.extend and buggy IE non-enumerable props

I’d like to extend the prototype of my custom constructor function with $.extend. The extender object contains a custom toString method that will not be enumerable in IE (8?). I didn’t find out whether jQuery fixes this problem internally or…
headacheCoder
  • 4,503
  • 8
  • 30
  • 33
0
votes
2 answers

Catching an exception vs. looping through a collection (the less stupid way)

A company that shall remain unnamed has IFormsCollection.GetForms("ObjectIndex") || IFormsCollection.GetForms(0) method that throws an exception if the Form isn't in the collection. It isn't IEnumerable
and requires either for() loops or…
Manchuwook
  • 341
  • 3
  • 15
0
votes
1 answer

Adding fixed size array to IEnumerable

This method gets: IEnumerable - in which every array is in fixed size (it represent relational data structure). DataEnumerable.Column[] - some metadata columns,mostly they will have the same value for all rows. Expected outcome: each…
Yosi Dahari
  • 6,794
  • 5
  • 24
  • 44
0
votes
3 answers

Awaiting a second level Task> in C#

I ran into a peculiar problem. Basically I'm writing a wrapper for an existing asynchronous class that reads data from the server. The original method that is in the library is something like this public async Task>…
Muhwu
  • 1,151
  • 1
  • 10
  • 26
0
votes
0 answers

Enumerability of properties in Javascript

How to create non-enumerable properties at construction ? function pp_urlfield( object ) {} pp_urlfield.prototype = Object.create( Object.prototype, { type_internal: { writable: true, configurable: true, enumerable: false, value:…
ehmicky
  • 1,915
  • 4
  • 20
  • 29