Class: MPrelude::Either

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat, Functor
Defined in:
lib/mprelude.rb

Overview

Maybe

Direct Known Subclasses

Left, Right

Defined Under Namespace

Classes: Left, Right

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap_error(*exceptions) ⇒ Either<Exception, Object>

Execute block and wrap error in left

Parameters:

  • exception (Class<Exception>)

Returns:



86
87
88
89
90
# File 'lib/mprelude.rb', line 86

def self.wrap_error(*exceptions)
  Right.new(yield)
rescue *exceptions => error
  Left.new(error)
end

Instance Method Details

#left?Boolean

Test for left constructor

Returns:

  • (Boolean)


95
96
97
# File 'lib/mprelude.rb', line 95

def left?
  instance_of?(Left)
end

#right?Boolean

Test for right constructor

Returns:

  • (Boolean)


102
103
104
# File 'lib/mprelude.rb', line 102

def right?
  instance_of?(Right)
end