Class: MPrelude::Either

Inherits:
Object
  • Object
show all
Includes:
AbstractType, Adamantium::Flat, RequireBlock
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:



84
85
86
87
88
# File 'lib/mprelude.rb', line 84

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)


93
94
95
# File 'lib/mprelude.rb', line 93

def left?
  instance_of?(Left)
end

#right?Boolean

Test for right constructor

Returns:

  • (Boolean)


100
101
102
# File 'lib/mprelude.rb', line 100

def right?
  instance_of?(Right)
end