Project

General

Profile

Actions

Feature #4890

closed

Enumerable#lazy

Added by yhara (Yutaka HARA) almost 13 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
[ruby-core:37164]

Description

=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


Files

lazy.rb (3.85 KB) lazy.rb yhara (Yutaka HARA), 06/16/2011 07:23 PM

Related issues 3 (0 open3 closed)

Related to Ruby master - Feature #4653: [PATCH 1/1] new method Enumerable#rude_mapRejectedmatz (Yukihiro Matsumoto)05/08/2011Actions
Related to Ruby master - Feature #708: Lazy Enumerator#select, Enumerator#map etc.Rejectedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Bug #7248: Shouldn't Enumerator::Lazy.new be private?Closedmarcandre (Marc-Andre Lafortune)10/31/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0