Class: Jrf::Reducers::Reduce
- Inherits:
-
Object
- Object
- Jrf::Reducers::Reduce
- Defined in:
- lib/jrf/reducers.rb
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(initial, finish_fn: nil, &step_fn) ⇒ Reduce
constructor
A new instance of Reduce.
- #step(value) ⇒ Object
Constructor Details
#initialize(initial, finish_fn: nil, &step_fn) ⇒ Reduce
Returns a new instance of Reduce.
8 9 10 11 12 |
# File 'lib/jrf/reducers.rb', line 8 def initialize(initial, finish_fn: nil, &step_fn) @acc = initial @step_fn = step_fn @finish_fn = finish_fn || ->(acc) { acc } end |
Instance Method Details
#finish ⇒ Object
18 19 20 |
# File 'lib/jrf/reducers.rb', line 18 def finish @finish_fn.call(@acc) end |
#step(value) ⇒ Object
14 15 16 |
# File 'lib/jrf/reducers.rb', line 14 def step(value) @acc = @step_fn.call(@acc, value) end |