Class: Jrf::Reducers::DecomposableReduce
- Defined in:
- lib/jrf/reducers.rb
Overview
A reducer whose partial accumulators can be merged across parallel workers.
Contract:
-
‘identity` is the neutral element for `merge_fn`: merge(identity, x) == x
-
‘initial` is always set to `identity` (the accumulator starts from the neutral element)
-
Any bias (e.g. sum’s ‘initial:` keyword) is applied in `finish_fn`, not in the starting accumulator
Instance Attribute Summary collapse
-
#merge_fn ⇒ Object
readonly
Returns the value of attribute merge_fn.
Instance Method Summary collapse
-
#initialize(identity, merge:, finish_fn: nil, &step_fn) ⇒ DecomposableReduce
constructor
A new instance of DecomposableReduce.
-
#merge_partial(other_acc) ⇒ Object
Merges another partial accumulator into this one.
-
#partial ⇒ Object
Returns the raw accumulator without applying finish_fn.
Methods inherited from Reduce
Constructor Details
#initialize(identity, merge:, finish_fn: nil, &step_fn) ⇒ DecomposableReduce
Returns a new instance of DecomposableReduce.
32 33 34 35 |
# File 'lib/jrf/reducers.rb', line 32 def initialize(identity, merge:, finish_fn: nil, &step_fn) super(identity, finish_fn: finish_fn, &step_fn) @merge_fn = merge end |
Instance Attribute Details
#merge_fn ⇒ Object (readonly)
Returns the value of attribute merge_fn.
30 31 32 |
# File 'lib/jrf/reducers.rb', line 30 def merge_fn @merge_fn end |
Instance Method Details
#merge_partial(other_acc) ⇒ Object
Merges another partial accumulator into this one.
43 44 45 |
# File 'lib/jrf/reducers.rb', line 43 def merge_partial(other_acc) @acc = @merge_fn.call(@acc, other_acc) end |
#partial ⇒ Object
Returns the raw accumulator without applying finish_fn.
38 39 40 |
# File 'lib/jrf/reducers.rb', line 38 def partial @acc end |