Project

either

0.0
No commit activity in last 3 years
No release in over 3 years
Stop using exceptions for control flow!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0

Runtime

 Project Readme

either

stop using exceptions for control flow with either types

Build Status Code Climate

An either can hold one of two possible things - a typical example would be either the successful result of a computation or an error explaining what went wrong.

By convention, a Left holds an error, while a Right holds the result of a successful computation.

Here's a simple example:

def divide x y
  y == 0 ? Left("Cannot divide by zero") : Right(x / y)
end

divide(4,2).match do |m|
  m.right { |res| puts "Division success: #{res}" }
  m.left  { |err| puts "Couldn't do this: #{err}" }
end
# The above will print "Division success: 2"

divide(4,0).match do |m|
  m.right { |res| puts "Division success: #{res}" }
  m.left  { |err| puts "Couldn't do this: #{err}" }
end
# The above will print "Couldn't do this: Cannot divide by zero"