Given a stream of streams. Than a ConcatenatedStream is obtained by concatenating these in the given order. A ConcatenatedStream is created by the methods Stream#concatenate or Stream#concatenate_collected send to a stream of streams or by the method + which concatenats two streams:
((1..3).create_stream + [4,5].create_stream).to_a ==> [1, 2, 3, 4, 5]
Creates a new ConcatenatedStream wrapping the stream of streams streamOfStreams.
# File lib/stream.rb, line 370 def initialize (streamOfStreams) super set_to_begin end
Same as at_end? the other way round.
# File lib/stream.rb, line 399 def at_beginning? # same algorithm as at_end? the other way round. Could we do it # with metaprogramming? @currentStream.at_beginning? and begin until streamOfStreams.at_beginning? dir, @dirOfLastMove = @dirOfLastMove, :backward s = streamOfStreams.basic_backward next if dir == :forward s.set_to_end if s.at_beginning? next else @currentStream = s return false end end reachedBoundary end end
If the current stream is at end, than at_end? has to look ahead to find a non empty in the stream of streams, which than gets the current stream.
# File lib/stream.rb, line 377 def at_end? @currentStream.at_end? and begin until streamOfStreams.at_end? dir, @dirOfLastMove = @dirOfLastMove, :forward s = streamOfStreams.basic_forward # if last move was backwards, then @currentStream is # equivalent to s. Move to next stream. next if dir == :backward s.set_to_begin if s.at_end? # empty stream? next # skip it else @currentStream = s return false # found non empty stream end end reachedBoundary # sets @dirOfLastMove and @currentStream end end
Returns the previous element of @currentStream. at_beginning? ensured that there is one.
# File lib/stream.rb, line 427 def basic_backward; @currentStream.basic_backward end
Returns the next element of @currentStream. at_end? ensured that there is one.
# File lib/stream.rb, line 424 def basic_forward; @currentStream.basic_forward end
Generated with the Darkfish Rdoc Generator 2.