Class: Sink::InputReduceWrapper

Inherits:
Object
  • Object
show all
Includes:
Sink
Defined in:
lib/coroutines/sink.rb

Instance Method Summary collapse

Methods included from Sink

#<=, #input_map, #input_reduce, #input_reject, #input_select

Constructor Details

#initialize(target, initial = nil, &block) ⇒ InputReduceWrapper



131
132
133
134
# File 'lib/coroutines/sink.rb', line 131

def initialize(target, initial=nil, &block)
  @target = target; @block = block
  @memo = initial
end

Instance Method Details

#<<(arg) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/coroutines/sink.rb', line 135

def <<(arg)
  if @memo.nil?
    @memo = arg
  else
    @memo = @block.call(@memo, arg)
  end
  self
end

#closeObject



143
144
145
146
# File 'lib/coroutines/sink.rb', line 143

def close
  @target << @memo
  @target.close
end