Class: Stream::BasicStream
Overview
The abstract super class of all concrete Classes implementing the Stream interface. Only used for including module Stream.
Direct Known Subclasses
CollectionStream, EmptyStream, ImplicitStream, IntervalStream, WrappedStream
Instance Method Summary collapse
-
#+(other) ⇒ Object
included
from Stream
Create a Stream::ConcatenatedStream by concatenatating the receiver and other_stream.
-
#at_beginning? ⇒ Boolean
included
from Stream
Returns false if the next #backward will return an element.
-
#at_end? ⇒ Boolean
included
from Stream
Returns false if the next #forward will return an element.
-
#backward ⇒ Object
included
from Stream
Move backward one position.
-
#collect(&mapping) ⇒ Object
included
from Stream
Create a Stream::MappedStream wrapper on self.
-
#concatenate ⇒ Object
included
from Stream
Create a Stream::ConcatenatedStream on self, which must be a stream of streams.
-
#concatenate_collected(&mapping) ⇒ Object
included
from Stream
Create a Stream::ConcatenatedStream, concatenated from streams build with the block for each element of self:.
-
#create_stream ⇒ Object
included
from Stream
create_stream is used for each Enumerable to create a stream for it.
-
#current ⇒ Object
included
from Stream
Returns the element returned by the last call of #forward.
-
#current_edge ⇒ Object
included
from Stream
Returns the array [#current,#peek].
-
#each ⇒ Object
included
from Stream
Implements the standard iterator used by module Enumerable, by calling set_to_begin and basic_forward until at_end? is true.
-
#empty? ⇒ Boolean
included
from Stream
Returns true if the stream is empty which is equivalent to at_end? and at_beginning? both being true.
-
#filtered(&block) ⇒ Object
included
from Stream
Return a Stream::FilteredStream which iterates over all my elements satisfying the condition specified by the block.
-
#first ⇒ Object
included
from Stream
Returns the first element of the stream.
-
#forward ⇒ Object
included
from Stream
Move forward one position.
-
#last ⇒ Object
included
from Stream
Returns the last element of the stream.
-
#modify(&block) ⇒ Object
included
from Stream
Create a Stream::ImplicitStream which wraps the receiver stream by modifying one or more basic methods of the receiver.
-
#move_backward_until ⇒ Object
included
from Stream
Move backward until the boolean block is not false and returns the element found.
-
#move_forward_until ⇒ Object
included
from Stream
Move forward until the boolean block is not false and returns the element found.
-
#peek ⇒ Object
included
from Stream
Returns the element returned by the last call of #backward.
-
#remove_first ⇒ Object
included
from Stream
Returns a Stream::ImplicitStream wrapping a Stream::FilteredStream, which eliminates the first element of the receiver.
-
#remove_last ⇒ Object
included
from Stream
Returns a Stream which eliminates the first element of the receiver.
-
#reverse ⇒ Object
included
from Stream
Create a Stream::ReversedStream wrapper on self.
-
#set_to_begin ⇒ Object
included
from Stream
Position the stream before its first element, i.e.
-
#set_to_end ⇒ Object
included
from Stream
Position the stream behind its last element, i.e.
-
#unwrapped ⇒ Object
included
from Stream
A Stream::WrappedStream should return the wrapped stream unwrapped.
Instance Method Details
#+(other) ⇒ Object Originally defined in module Stream
Create a Stream::ConcatenatedStream by concatenatating the receiver and other_stream
(%w(a b c).create_stream + [4,5].create_stream).to_a
==> ["a", "b", "c", 4, 5]
#at_beginning? ⇒ Boolean Originally defined in module Stream
Returns false if the next #backward will return an element.
#at_end? ⇒ Boolean Originally defined in module Stream
Returns false if the next #forward will return an element.
#backward ⇒ Object Originally defined in module Stream
Move backward one position. Returns the source of current_edge. Raises Stream::EndOfStreamException if at_beginning? is true.
#collect(&mapping) ⇒ Object Originally defined in module Stream
Create a Stream::MappedStream wrapper on self. Instead of returning the stream element on each move, the value of calling mapping is returned instead. See Stream::MappedStream for examples.
#concatenate ⇒ Object Originally defined in module Stream
Create a Stream::ConcatenatedStream on self, which must be a stream of streams.
#concatenate_collected(&mapping) ⇒ Object Originally defined in module Stream
Create a Stream::ConcatenatedStream, concatenated from streams build with the block for each element of self:
s = [1, 2, 3].create_stream.concatenate_collected { |i|
[i,-i].create_stream
}.
s.to_a ==> [1, -1, 2, -2, 3, -3]
#create_stream ⇒ Object Originally defined in module Stream
create_stream is used for each Enumerable to create a stream for it. A Stream as an Enumerable returns itself.
#current ⇒ Object Originally defined in module Stream
Returns the element returned by the last call of #forward. If at_beginning? is true self is returned.
#current_edge ⇒ Object Originally defined in module Stream
Returns the array [#current,#peek].
#each ⇒ Object Originally defined in module Stream
Implements the standard iterator used by module Enumerable, by calling set_to_begin and basic_forward until at_end? is true.
#empty? ⇒ Boolean Originally defined in module Stream
Returns true if the stream is empty which is equivalent to at_end? and at_beginning? both being true.
#filtered(&block) ⇒ Object Originally defined in module Stream
Return a Stream::FilteredStream which iterates over all my elements satisfying the condition specified by the block.
#first ⇒ Object Originally defined in module Stream
Returns the first element of the stream. This is accomplished by calling set_to_begin and #forward, which means a state change.
#forward ⇒ Object Originally defined in module Stream
Move forward one position. Returns the target of current_edge. Raises Stream::EndOfStreamException if at_end? is true.
#last ⇒ Object Originally defined in module Stream
Returns the last element of the stream. This is accomplished by calling set_to_begin and #backward, which means a state change.
#modify(&block) ⇒ Object Originally defined in module Stream
Create a Stream::ImplicitStream which wraps the receiver stream by modifying one or more basic methods of the receiver. As an example the method remove_first uses #modify to create an ImplicitStream which filters the first element away.
#move_backward_until ⇒ Object Originally defined in module Stream
Move backward until the boolean block is not false and returns the element found. Returns nil if no object matches.
#move_forward_until ⇒ Object Originally defined in module Stream
Move forward until the boolean block is not false and returns the element found. Returns nil if no object matches.
This is similar to #detect, but starts the search from the current position. #detect, which is inherited from Enumerable uses #each, which implicitly calls #set_to_begin.
#peek ⇒ Object Originally defined in module Stream
Returns the element returned by the last call of #backward. If at_end? is true self is returned.
#remove_first ⇒ Object Originally defined in module Stream
Returns a Stream::ImplicitStream wrapping a Stream::FilteredStream, which eliminates the first element of the receiver.
(1..3).create_stream.remove_first.to_a ==> [2,3]
#remove_last ⇒ Object Originally defined in module Stream
Returns a Stream which eliminates the first element of the receiver.
(1..3).create_stream.remove_last.to_a ==> [1,2]
Take a look at the source. The implementation is inefficient but elegant.
#reverse ⇒ Object Originally defined in module Stream
Create a Stream::ReversedStream wrapper on self.
#set_to_begin ⇒ Object Originally defined in module Stream
Position the stream before its first element, i.e. the next #forward will return the first element.
#set_to_end ⇒ Object Originally defined in module Stream
Position the stream behind its last element, i.e. the next #backward will return the last element.
#unwrapped ⇒ Object Originally defined in module Stream
A Stream::WrappedStream should return the wrapped stream unwrapped. If the stream is not a wrapper around another stream it simply returns itself.