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(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.



421
422
423
424
# File 'lib/stream.rb', line 421

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)


427
428
429
# File 'lib/stream.rb', line 427

def at_beginning?
  wrapped_stream.at_end?
end

#at_end?Boolean

Returns true if the wrapped stream is at_beginning?.

Returns:

  • (Boolean)


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

def at_end?
  wrapped_stream.at_beginning?
end

#basic_backwardObject

Moves the wrapped stream one step forward.



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

def basic_backward
  wrapped_stream.basic_forward
end

#basic_forwardObject

Moves the wrapped stream one step backward.



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

def basic_forward
  wrapped_stream.basic_backward
end

#set_to_beginObject

Sets the wrapped stream to the end.



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

def set_to_begin
  wrapped_stream.set_to_end
end

#set_to_endObject

Sets the wrapped stream to the beginning.



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

def set_to_end
  wrapped_stream.set_to_begin
end