From: Akinori MUSHA <knu@...>
Date: 2011-10-31T14:27:49+09:00
Subject: [ruby-core:40548] [ruby-trunk - Feature #4890] Enumerable#lazy


Issue #4890 has been updated by Akinori MUSHA.


One thing I should comment on the sample implementation: Enumerable::Lazy should not inherit from Enumerator which includes Enumerable.

Enumerable::Lazy has the method set similar to Enumerable but their behavior is different.  Enumerable's methods defined by third party libraries (that may be non-lazy) should not automatically be exposed to Enumerable::Lazy, who must want to offer (redefine) lazy counterparts of those methods soon or later.

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