Class: Stream::CollectionStream

### Home Classes Methods

### In Files

- lib/stream.rb

### Parent

Stream::BasicStream

### Methods

- ::new
- #at_beginning?
- #at_end?
- #basic_backward
- #basic_current
- #basic_forward
- #basic_peek
- #set_to_begin
- #set_to_end

### Class/Module Index

Quicksearch

- Stream
- Stream::BasicStream
- Stream::CollectionStream
- Stream::ConcatenatedStream
- Stream::EmptyStream
- Stream::EndOfStreamException
- Stream::FilteredStream
- Stream::ImplicitStream
- Stream::IntervalStream
- Stream::MappedStream
- Stream::ReversedStream
- Stream::WrappedStream
- Array
- Enumerable
- Generator
- Object

No matching classes.

# Stream::CollectionStream

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.

### Attributes

pos[R]

### Public Class Methods

new(seq) click to toggle source

Creates a new CollectionStream for the indexable sequence seq.

    # File lib/stream.rb, line 146
    def initialize(seq)
      @seq = seq
      set_to_begin
    end

### Public Instance Methods

at_beginning?() click to toggle source

    # File lib/stream.rb, line 152
    def at_beginning?; @pos < 0; end

at_end?() click to toggle source

    # File lib/stream.rb, line 151
    def at_end?; @pos + 1 >= @seq.size; end

basic_backward() click to toggle source

    # File lib/stream.rb, line 161
    def basic_backward; r = @seq[@pos]; @pos -= 1; r; end

basic_forward() click to toggle source

    # File lib/stream.rb, line 160
    def basic_forward; @pos += 1; @seq[@pos]; end

set_to_begin() click to toggle source

    # File lib/stream.rb, line 157
    def set_to_begin; @pos = -1; end

set_to_end() click to toggle source

    # File lib/stream.rb, line 158
    def set_to_end; @pos = @seq.size - 1; end

### Protected Instance Methods

basic_current() click to toggle source

basic_current and basic_peek can be implemented more efficiently than in superclass

    # File lib/stream.rb, line 167
    def basic_current; @seq[@pos]; end

basic_peek() click to toggle source

    # File lib/stream.rb, line 168
    def basic_peek; @seq[@pos+1]; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.