Class: Stream::CollectionStream
Overview
A CollectionStream can be used as an external iterator for each interger-indexed collection. The state of the iterator is stored in instance variable @pos.
A CollectionStream for an array is created by the method Array#create_stream.
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
Creates a new CollectionStream for the indexable sequence seq.
146
147
148
149
|
# File 'lib/stream.rb', line 146
def initialize(seq)
@seq = seq
set_to_begin
end
|
Instance Attribute Details
#pos ⇒ Object
Returns the value of attribute pos.
143
144
145
|
# File 'lib/stream.rb', line 143
def pos
@pos
end
|
Instance Method Details
#at_beginning? ⇒ Boolean
152
|
# File 'lib/stream.rb', line 152
def at_beginning?; @pos < 0; end
|
#at_end? ⇒ Boolean
151
|
# File 'lib/stream.rb', line 151
def at_end?; @pos + 1 >= @seq.size; end
|
#basic_backward ⇒ Object
161
|
# File 'lib/stream.rb', line 161
def basic_backward; r = @seq[@pos]; @pos -= 1; r; end
|
#basic_forward ⇒ Object
160
|
# File 'lib/stream.rb', line 160
def basic_forward; @pos += 1; @seq[@pos]; end
|
#set_to_begin ⇒ Object
157
|
# File 'lib/stream.rb', line 157
def set_to_begin; @pos = -1; end
|
#set_to_end ⇒ Object
158
|
# File 'lib/stream.rb', line 158
def set_to_end; @pos = @seq.size - 1; end
|