Class: Transducers::Reducer
- Inherits:
-
Object
- Object
- Transducers::Reducer
- Defined in:
- lib/transducers.rb
Instance Method Summary collapse
- #complete(result) ⇒ Object
- #init ⇒ Object
-
#initialize(init, sym = nil, &block) ⇒ Reducer
constructor
A new instance of Reducer.
- #step(result, input) ⇒ Object
Constructor Details
#initialize(init, sym = nil, &block) ⇒ Reducer
Returns a new instance of Reducer.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/transducers.rb', line 126 def initialize(init, sym=nil, &block) raise ArgumentError.new("No init provided") if init == :no_init_provided @init = init if sym @sym = sym (class << self; self; end).class_eval do def step(result, input) result.send(@sym, input) end end else @block = block (class << self; self; end).class_eval do def step(result, input) @block.call(result, input) end end end end |
Instance Method Details
#complete(result) ⇒ Object
147 |
# File 'lib/transducers.rb', line 147 def complete(result) result end |
#init ⇒ Object
146 |
# File 'lib/transducers.rb', line 146 def init() @init end |
#step(result, input) ⇒ Object
148 149 150 |
# File 'lib/transducers.rb', line 148 def step(result, input) # placeholder for docs - overwritten in initalize end |