Class: DStream::Scan

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

Instance Method Summary collapse

Methods inherited from Abstract

#inspect

Constructor Details

#initialize(init, &block) ⇒ Scan

Returns a new instance of Scan.



35
36
37
38
# File 'lib/d-stream.rb', line 35

def initialize(init, &block)
  @init = init
  @block = block
end

Instance Method Details

#apply(s) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/d-stream.rb', line 40

def apply(s)
  Enumerator.new do |y|
    acc = @init

    s.each do |e|
      acc = @block.call(acc, e)
      y << acc
    end
  end.lazy
end