Class: Stream::ReversedStream

Inherits:
WrappedStream show all
Defined in:
lib/stream.rb

Overview

Each reversable stream (a stream that implements #backward and at_beginning?) can be wrapped by a ReversedStream.

A ReversedStream is created by the method #reverse:

(1..6).create_stream.reverse.to_a ==> [6, 5, 4, 3, 2, 1]

Instance Attribute Summary

Attributes inherited from WrappedStream

#wrapped_stream

Instance Method Summary collapse

Methods inherited from WrappedStream

#unwrapped

Methods included from Stream

#+, #backward, #collect, #concatenate, #concatenate_collected, #create_stream, #current, #current_edge, #each, #empty?, #filtered, #first, #forward, #last, #modify, #move_backward_until, #move_forward_until, #peek, #remove_first, #remove_last, #reverse, #unwrapped

Methods included from Enumerable

#create_stream

Constructor Details

#initialize(otherStream) ⇒ ReversedStream

Create a reversing wrapper for the reversable stream otherStream. If otherStream does not support backward moving a NotImplementedError is signaled on the first backward move.


311
312
313
314
# File 'lib/stream.rb', line 311

def initialize (otherStream)
  super otherStream
  set_to_begin
end

Instance Method Details

#at_beginning?Boolean

Returns true if the wrapped stream is at_end?.

Returns:

  • (Boolean)

317
# File 'lib/stream.rb', line 317

def at_beginning?; wrapped_stream.at_end?; end

#at_end?Boolean

Returns true if the wrapped stream is at_beginning?.

Returns:

  • (Boolean)

319
# File 'lib/stream.rb', line 319

def at_end?; wrapped_stream.at_beginning?; end

#basic_backwardObject

Moves the wrapped stream one step forward.


324
# File 'lib/stream.rb', line 324

def basic_backward; wrapped_stream.basic_forward; end

#basic_forwardObject

Moves the wrapped stream one step backward.


322
# File 'lib/stream.rb', line 322

def basic_forward; wrapped_stream.basic_backward; end

#set_to_beginObject

Sets the wrapped stream to the end.


329
# File 'lib/stream.rb', line 329

def set_to_begin; wrapped_stream.set_to_end; end

#set_to_endObject

Sets the wrapped stream to the beginning.


327
# File 'lib/stream.rb', line 327

def set_to_end; wrapped_stream.set_to_begin; end