0 Replies - 2321 Views - Last Post: 19 February 2014 - 08:50 PM Rate Topic: -----

#1 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1381
  • View blog
  • Posts: 3,511
  • Joined: 28-November 09

[Gem] QEnumerable - Query against collections

Post icon  Posted 19 February 2014 - 08:50 PM

Inspired a tinge by SQL and Haskell.

https://github.com/b...ver/qenumerable

Let's get ourselves a collection to use:

class Object; include QEnumerable end

brandon = Person.new('brandon', 23, 'm')
john    = Person.new('john',    42, 'm')
jill    = Person.new('jill',    31, 'f')
alice   = Person.new('alice',   50, 'f')
zeke    = Person.new('zeke',    18, 'm')

people = [brandon, john, jill, alice, zeke]



Select Where

Select all objects where params match:

people.select_where name: /^j/
# => [john, jill]



Reject Where

Reject all objects where params match:

people.reject_where name: /^j/
# => [brandon, alice, zeke]


Find Where

Finds the first object where params match:

people.find_where name: /^j/
# => john

This post has been edited by Lemur: 19 February 2014 - 09:01 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1