No commit activity in last 3 years
No release in over 3 years
Enumerator::Lazy support for compact, uniq, and flatten
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
 Project Readme

Lazier Enumerators Build Status

This library adds support for uniq, flatten, and compact to Ruby 2.0's Enumerator::Lazy.

Basic Usage

Instead of

enumerable.flatten.compact.uniq.map(&:uppercase)

which would loop through the enumerable multiple times, you can do

require 'lazier_enumerator'

enumerable.lazy.flatten.compact.uniq.map(&:uppercase).force

after running

gem install lazier_enumerator

which will do the same thing, but lazily, only loading one element of enumerable at a time and only looping through it once.

In practice, based on benchmarks of this library and Enumerator::Lazy itself, for most enumerables lazy enumeration is actually ~2x slower than normal enumeration -- so use this library with a grain of salt :)

If you want something even lazier (and slower)

You can require lazier_enumerator/even_lazier, which will define additional methods on Enumerable to provide lazy support for a variety of operations -- but in practice they take ~10x longer than their industrious versions.

require 'lazier_enumerator/even_lazier'

# pass procs or symbols, not blocks, to lmap/lselect/lreject

[1,-2,[3,nil,[4]]].lflatten.lcompact.luniq.lmap(:abs).lselect(:even?).each do |i|
  puts i
end

# => 2 4