module Enumerable
Enumerable#lazy
example implementation¶ ↑
Enumerable#lazy
returns an instance of Enumerable::Lazy
. You can use it just like as normal Enumerable
object, except these methods act as 'lazy':
- map collect - select find_all - reject - grep - drop - drop_while - take_while - flat_map collect_concat - zip
Example¶ ↑
This code prints the first 100 primes.
require 'prime' INFINITY = 1.0 / 0 p (1..INFINITY).lazy.select{|m| m.prime?}.take(100)
Acknowledgements¶ ↑
Inspired by https://github.com/antimon2/enumerable_lz http://jp.rubyist.net/magazine/?0034-Enumerable_lz (ja)
Public Instance Methods
lazy()
click to toggle source
# File lib/enumerable/lazy.rb, line 31 def lazy Lazy.new(self) end