Class: Sink::InputReduceWrapper
- Includes:
- Sink
- Defined in:
- lib/coroutines/sink.rb
Instance Method Summary collapse
- #<<(arg) ⇒ Object
- #close ⇒ Object
-
#initialize(target, initial = nil, &block) ⇒ InputReduceWrapper
constructor
A new instance of InputReduceWrapper.
Methods included from Sink
#<=, #input_map, #input_reduce, #input_reject, #input_select
Constructor Details
#initialize(target, initial = nil, &block) ⇒ InputReduceWrapper
Returns a new instance of 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 |
#close ⇒ Object
143 144 145 146 |
# File 'lib/coroutines/sink.rb', line 143 def close @target << @memo @target.close end |