Class: Jrf::Reducers::Reduce

Inherits:
Object
  • Object
show all
Defined in:
lib/jrf/reducers.rb

Instance Method Summary collapse

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

#finishObject



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