Class: Stream::CollectionStream
- Inherits:
-
BasicStream
- Object
- BasicStream
- Stream::CollectionStream
- Defined in:
- lib/stream.rb
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.
Constant Summary
Constants included from Stream
Instance Attribute Summary collapse
-
#pos ⇒ Object
readonly
Returns the value of attribute pos.
Instance Method Summary collapse
- #at_beginning? ⇒ Boolean
- #at_end? ⇒ Boolean
- #basic_backward ⇒ Object
- #basic_forward ⇒ Object
-
#initialize(seq) ⇒ CollectionStream
constructor
Creates a new CollectionStream for the indexable sequence seq.
-
#set_to_begin ⇒ Object
positioning.
- #set_to_end ⇒ Object
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
Constructor Details
#initialize(seq) ⇒ CollectionStream
Creates a new CollectionStream for the indexable sequence seq.
204 205 206 207 |
# File 'lib/stream.rb', line 204 def initialize(seq) @seq = seq set_to_begin end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
200 201 202 |
# File 'lib/stream.rb', line 200 def pos @pos end |
Instance Method Details
#at_beginning? ⇒ Boolean
213 214 215 |
# File 'lib/stream.rb', line 213 def at_beginning? @pos < 0 end |
#at_end? ⇒ Boolean
209 210 211 |
# File 'lib/stream.rb', line 209 def at_end? @pos + 1 >= @seq.size end |
#basic_backward ⇒ Object
232 233 234 235 |
# File 'lib/stream.rb', line 232 def basic_backward r = @seq[@pos] @pos -= 1; r end |
#basic_forward ⇒ Object
227 228 229 230 |
# File 'lib/stream.rb', line 227 def basic_forward @pos += 1 @seq[@pos] end |
#set_to_begin ⇒ Object
positioning
219 220 221 |
# File 'lib/stream.rb', line 219 def set_to_begin @pos = -1 end |
#set_to_end ⇒ Object
223 224 225 |
# File 'lib/stream.rb', line 223 def set_to_end @pos = @seq.size - 1 end |