Class: DStream::WithNext

Inherits:
Abstract show all
Defined in:
lib/d-stream.rb

Instance Method Summary collapse

Methods inherited from Abstract

#inspect

Instance Method Details

#apply(s) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/d-stream.rb', line 143

def apply(s)
  Enumerator.new do |y|
    prev = nil
    have_prev = false

    s.each do |e|
      if have_prev
        y << [prev, e]
      else
        have_prev = true
      end
      prev = e
    end
    y << [prev, nil]
  end.lazy
end