module Either
Public Class Methods
match(e, left:, right:)
click to toggle source
# File lib/either.rb, line 17 def self.match(e, left:, right:) if e.right? right.call(e.send(:val)) elsif e.left? left.call(e.send(:val)) end end
new(&block)
click to toggle source
# File lib/either.rb, line 4 def self.new(&block) val = begin block.call() rescue Exception => e e end if val.nil? || val.is_a?(Exception) Left.new(val) else Right.new(val) end end