Issue #4890 has been updated by Shugo Maeda.


Shugo Maeda wrote:
> FYI, Scala has a similar method called view.  I don't know whether
> the name view is better than lazy because I'm not a native English speaker.
(snip)
> In Ruby, results are always arrays, so we can use to_a instead of force.
> But the name force looks better than to_a for me.

If the method force is added, delay sounds more natural than lazy or view for me. 

  p (1..10).delay.map{|i| i+1}.map{|i| i+2}.force

That's just off the top of my head, and it may be confusing.

----------------------------------------
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

((<URL:https://gist.github.com/1028609>))
(also attached to this ticket)

=end



-- 
http://redmine.ruby-lang.org