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.
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.
195 196 197 198 |
# File 'lib/stream.rb', line 195 def initialize(seq) @seq = seq set_to_begin end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
192 193 194 |
# File 'lib/stream.rb', line 192 def pos @pos end |
Instance Method Details
#at_beginning? ⇒ Boolean
204 205 206 |
# File 'lib/stream.rb', line 204 def at_beginning? @pos < 0 end |
#at_end? ⇒ Boolean
200 201 202 |
# File 'lib/stream.rb', line 200 def at_end? @pos + 1 >= @seq.size end |
#basic_backward ⇒ Object
223 224 225 226 |
# File 'lib/stream.rb', line 223 def basic_backward r = @seq[@pos] @pos -= 1; r end |
#basic_forward ⇒ Object
218 219 220 221 |
# File 'lib/stream.rb', line 218 def basic_forward @pos += 1 @seq[@pos] end |
#set_to_begin ⇒ Object
positioning
210 211 212 |
# File 'lib/stream.rb', line 210 def set_to_begin @pos = -1 end |
#set_to_end ⇒ Object
214 215 216 |
# File 'lib/stream.rb', line 214 def set_to_end @pos = @seq.size - 1 end |