Class: FunctionalLightService::Organizer::ReduceWhile

Inherits:
Object
  • Object
show all
Defined in:
lib/functional-light-service/organizer/reduce_while.rb

Class Method Summary collapse

Class Method Details

.run(organizer, condition_block, steps) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/functional-light-service/organizer/reduce_while.rb', line 6

def self.run(organizer, condition_block, steps)
  ->(ctx) do
    return ctx if ctx.stop_processing?

    reset_skip(ctx)

    Array(steps).each do |step|
      break unless condition_block.call(ctx)

      ctx = organizer.with(ctx).reduce([step])
      break if ctx.stop_processing?
    end

    reset_skip(ctx)

    ctx
  end
end