From: Shugo Maeda Date: 2011-10-31T14:39:37+09:00 Subject: [ruby-core:40549] [ruby-trunk - Feature #4890] Enumerable#lazy Issue #4890 has been updated by Shugo Maeda. Akinori MUSHA wrote: > The idea of laziness can be or should be sublimated into a revamp of the Enumerable framework. > > - Make every Enumerable object act like an immutable array by defining Array methods ([], size/length, +, -, join, etc.) > - Then make some of the methods returning an array (map, select, zip, etc.) return an Enumerable(::Lazy or object of the receiver's class) It breaks compatibility, so may not be acceptable in Ruby 2.0. Or It may be acceptable depending on Matz's definition of "100% compatible." > This way we can "hide" the lazy class and basically make everything lazy where appropriate. It may be better to specify explicitly what is lazy and what is not. In Ruby the difference is more important than functional languages. ---------------------------------------- Feature #4890: Enumerable#lazy http://redmine.ruby-lang.org/issues/4890 Author: Yutaka HARA Status: Open Priority: Normal Assignee: Yukihiro Matsumoto Category: core Target version: 2.0 =begin = Example Print first 100 primes which are in form of n^2+1 require 'prime' INFINITY = 1.0 / 0 p (1..INFINITY).lazy.map{|n| n**2+1}.select{|m| m.prime?}.take(100) (Example taken from enumerable_lz; thanks @antimon2) = Description Enumerable#lazy returns an instance of Enumerable::Lazy. This is the only method added to the existing bulit-in classes. Lazy is a subclass of Enumerator, which includes Enumerable. So you can call any methods of Enumerable on Lazy, except methods like map, select, etc. are redefined as 'lazy' versions. = Sample implementation (()) (also attached to this ticket) =end -- http://redmine.ruby-lang.org