D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Enumerator
/
Lazy
/
Filename :
new-c.ri
back
Copy
U:RDoc::AnyMethod[iI"new:ETI"Enumerator::Lazy::new;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [ I"OCreates a new Lazy enumerator. When the enumerator is actually enumerated ;TI"N(e.g. by calling #force), +obj+ will be enumerated and each value passed ;TI"Jto the given block. The block can yield values back using +yielder+. ;TI"6For example, to create a "filter+map" enumerator:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"def filter_map(sequence) ;TI"0 Lazy.new(sequence) do |yielder, *values| ;TI" result = yield *values ;TI"% yielder << result if result ;TI" end ;TI" end ;TI" ;TI"Bfilter_map(1..Float::INFINITY) {|i| i*i if i.even?}.first(5) ;TI"#=> [4, 16, 36, 64, 100];T:@format0: @fileI"enumerator.c;T:0@omit_headings_from_table_of_contents_below0I":Lazy.new(obj, size=nil) { |yielder, *values| block } ;T0[ I"(*args);T@FI" Lazy;TcRDoc::NormalClass00