Project

General

Profile

Actions

Feature #707

closed

Documentation for Enumerator chaining

Added by candlerb (Brian Candler) over 13 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:19679]

Description

=begin
Enumerators now support a horizontal filter/chaining pattern:

generator.filter1 { ... }.filter2 { ... }.filter3 { ... }.consumer

The overall pattern for a filter is:

Enumerator.new do |y|
source.each do |input| # filter INPUT
...
y << output # filter OUTPUT
end
end

This is extremely powerful. However it is not obvious to the newcomer that this is even possible. (Confusion may arise where people know Ruby 1.8's Enumerator, which cannot do this)

So I would just like to see this pattern documented with an example, e.g. under ri Enumerator.new

I have attached a possible example. Note that I have written my Fib generator in a style familiar from ruby-1.8, to emphasise that the Enumerator filter doesn't require a specially-written generator.
=end


Files

fib.rb (676 Bytes) fib.rb candlerb (Brian Candler), 11/03/2008 06:41 PM
enumerator.c.lazy.patch (2.7 KB) enumerator.c.lazy.patch drbrain (Eric Hodel), 02/11/2012 11:01 AM
Actions

Also available in: Atom PDF