Module: Resulting::Handler

Includes:
Helpers
Defined in:
lib/resulting/handler.rb

Class Method Summary collapse

Methods included from Helpers

included

Class Method Details

.handle(result_or_value, wrapper: ->(&blk) { return blk.call }) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/resulting/handler.rb', line 5

def self.handle(result_or_value, wrapper: ->(&blk) { return blk.call })
  wrapper.call do
    result = Resulting::Result.wrap(result_or_value)

    return result if result.failure?

    success = yield

    result.class.new(success, result.value)
  end
end