Case equality

Case equality

Monads allow to use default ruby case operator for matching result:

case value
when Some(1), Some(2) then :one_or_two
when Some(3..5) then :three_to_five
else
  :something_else
end

You can use specific Failure options too:

case value
when Success then [:ok, value.value!]
when Failure(TimeoutError) then [:timeout]
when Failure(ConnectionClosed) then [:net_error]
when Failure then [:generic_error]
else
  raise "Unhandled case"
end

Nested structures

case value
when Success(None()) then :nothing
when Success(Some { |x| x > 10 }) then :something
when Success(Some) then :something_else
when Failure then :error
end

octocatEdit on GitHub