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]

Constant Summary

Constants included from Stream

VERSION

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(other_stream) ⇒ ReversedStream

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



431
432
433
434
# File 'lib/stream.rb', line 431

def initialize(other_stream)
  super other_stream
  set_to_begin
end

Instance Method Details

#at_beginning?Boolean

Returns true if the wrapped stream is at_end?.

Returns:

  • (Boolean)


437
438
439
# File 'lib/stream.rb', line 437

def at_beginning?
  wrapped_stream.at_end?
end

#at_end?Boolean

Returns true if the wrapped stream is at_beginning?.

Returns:

  • (Boolean)


442
443
444
# File 'lib/stream.rb', line 442

def at_end?
  wrapped_stream.at_beginning?
end

#basic_backwardObject

Moves the wrapped stream one step forward.



452
453
454
# File 'lib/stream.rb', line 452

def basic_backward
  wrapped_stream.basic_forward
end

#basic_forwardObject

Moves the wrapped stream one step backward.



447
448
449
# File 'lib/stream.rb', line 447

def basic_forward
  wrapped_stream.basic_backward
end

#set_to_beginObject

Sets the wrapped stream to the end.



462
463
464
# File 'lib/stream.rb', line 462

def set_to_begin
  wrapped_stream.set_to_end
end

#set_to_endObject

Sets the wrapped stream to the beginning.



457
458
459
# File 'lib/stream.rb', line 457

def set_to_end
  wrapped_stream.set_to_begin
end