Class: Stream::IntervalStream
- Inherits:
-
BasicStream
- Object
- BasicStream
- Stream::IntervalStream
- Defined in:
- lib/stream.rb
Overview
A simple Iterator for iterating over a sequence of integers starting from zero up to a given upper bound. Mainly used by Stream::FilteredStream. Could be made private but if somebody needs it here it is. Is there a better name for it?
The upper bound is stored in the instance variable @stop which can be incremented dynamically by the method increment_stop.
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
-
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
-
#initialize(stop = 0) ⇒ IntervalStream
constructor
Create a new IntervalStream with upper bound stop.
- #set_to_begin ⇒ Object
- #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(stop = 0) ⇒ IntervalStream
Create a new IntervalStream with upper bound stop. stop - 1 is the last element. By default stop is zero which means that the stream is empty.
265 266 267 268 |
# File 'lib/stream.rb', line 265 def initialize(stop = 0) @stop = stop - 1 set_to_begin end |
Instance Attribute Details
#pos ⇒ Object (readonly)
Returns the value of attribute pos.
260 261 262 |
# File 'lib/stream.rb', line 260 def pos @pos end |
Instance Method Details
#at_beginning? ⇒ Boolean
270 271 272 |
# File 'lib/stream.rb', line 270 def at_beginning? @pos < 0 end |
#at_end? ⇒ Boolean
274 275 276 |
# File 'lib/stream.rb', line 274 def at_end? @pos == @stop end |
#basic_backward ⇒ Object
295 296 297 298 |
# File 'lib/stream.rb', line 295 def basic_backward @pos -= 1 @pos + 1 end |
#basic_forward ⇒ Object
291 292 293 |
# File 'lib/stream.rb', line 291 def basic_forward @pos += 1 end |
#increment_stop(incr = 1) ⇒ Object
Increment the upper bound by incr.
287 288 289 |
# File 'lib/stream.rb', line 287 def increment_stop(incr = 1) @stop += incr end |
#set_to_begin ⇒ Object
282 283 284 |
# File 'lib/stream.rb', line 282 def set_to_begin @pos = -1 end |
#set_to_end ⇒ Object
278 279 280 |
# File 'lib/stream.rb', line 278 def set_to_end @pos = @stop end |