class Stream::MappedStream

The analog to Enumerable#collect for a stream is a MappedStream wrapping another stream. A MappedStream is created by the method collect, thus modifying the behavior mixed in by Enumerable:

(1..5).create_stream.collect {|x| x**2}.type ==> Stream::MappedStream
(1..5).collect {|x| x**2} ==> [1, 4, 9, 16, 25]
(1..5).create_stream.collect {|x| x**2}.to_a ==> [1, 4, 9, 16, 25]

Public Class Methods

new(other_stream, &mapping) click to toggle source

Creates a new MappedStream wrapping other_stream which calls the block mapping on each move.

Calls superclass method Stream::WrappedStream::new
    # File lib/stream.rb
469 def initialize(other_stream, &mapping)
470   super other_stream
471   @mapping = mapping
472 end

Public Instance Methods

basic_backward() click to toggle source

Apply the stored closure for the previous element in the wrapped stream and return the result.

Calls superclass method Stream::WrappedStream#basic_backward
    # File lib/stream.rb
482 def basic_backward
483   @mapping.call(super)
484 end
basic_forward() click to toggle source

Apply the stored closure for the next element in the wrapped stream and return the result.

Calls superclass method Stream::WrappedStream#basic_forward
    # File lib/stream.rb
476 def basic_forward
477   @mapping.call(super)
478 end