Class: Sink::InputReduceWrapper
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
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
|
143
144
145
146
|
# File 'lib/coroutines/sink.rb', line 143
def close
@target << @memo
@target.close
end
|