Project

lazing

0.0
No commit activity in last 3 years
No release in over 3 years
Lazy equivalents for many of the methods in Enumerable
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Lazing

Lazing provides lazy equivalents for many of the methods in Ruby's standard Enumerable module. The lazy variants all end in 'ing', hence the name.

For example:

>> (1..20).selecting {|x| raise 'boom' if x == 6; x.odd?}.first(3)
 => [1, 3, 5]

Compare the above with the behavior of the non-lazy standard version:

>> (1..20).select {|x| raise 'boom' if x == 6; x.odd?}.first(3)
RuntimeError: boom
  from (irb):4:in `block in irb_binding'
  from (irb):4:in `each'
  from (irb):4:in `select'
  from (irb):4
  from irb:17:in `<main>'

Lazy Methods

Lazing defines the following lazy filter methods:

  • finding_all
  • rejecting
  • selecting

Lazing defines the following lazy transformation methods:

  • collecting
  • mapping

Supported Rubies

Lazing has been testing with:

  • Ruby 1.8.7-p302
  • Ruby 1.9.2-p0
  • JRuby 1.5.5
  • Rubinius 1.1.1

Installation

Lazing is distributed as a gem. To install, use the command:

gem install lazing

Obtaining the Latest Version

Lazing is hosted on github at http://github.com/gregspurrier/lazing.

A local clone of the repository can be obtained via:

git clone git://github.com/gregspurrier/lazing.git

Related work

After implementing select_first for a project I was working on, I searched for lazy enumeration support in Ruby. I came across this blog post and it became the inspiration for the 1.9.x implementation of Lazing.

I later discovered that my 1.9.2 implementation of selecting is almost identical to the infinite_select example given in Programming Ruby: The Pragmatic Programmers' Guide by Dave Thomas.

The implementation for Rubies other than MRI 1.9.x is heavily influenced by Scheme's streams as described in The Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman.

License

Lazing is Copyright (c) 2010 by Greg Spurrier and released under the terms of the MIT License. Please see LICENSE.txt for details.