Feature #707: Documentation for Enumerator chaining
http://redmine.ruby-lang.org/issues/show/707

Author: Brian Candler
Status: Open, Priority: Low
Category: DOC, Target version: 1.9.x

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.


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