Closed citizen428 closed 4 years ago
It seems like the first value in the return "tuple" is actually switched. If we treat the first return value as error instead of success everything works as expected:
require 'dry/effects'
class RunDivision
include Dry::Effects::Handler.Interrupt(:division_by_zero, as: :catch_zero_division)
def call
error, answer = catch_zero_division do
yield
end
if error
:error
else
answer
end
end
end
class Divide
include Dry::Effects.Interrupt(:division_by_zero)
def call(dividend, divisor)
if divisor.zero?
division_by_zero
else
dividend / divisor
end
end
end
run = RunDivision.new
divide = Divide.new
app = -> a, b { run.() { divide.(a, b) } }
run = RunDivision.new
divide = Divide.new
app = -> a, b { run.() { divide.(a, b) } }
app.(10, 2) # => 5
app.(10, 2) # => :error
Thanks!
Describe the bug
Executing the code from the Basic Usage of the
Interrupt
guide does not yield the expected result.To Reproduce
Execute the code from the example:
Expected behavior
Expected:
Got:
Your environment
I'd look into it myself, but won't have time today.