Class: TTY::Option::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/option/result.rb

Overview

A monad that respresents success and failure conditions

Direct Known Subclasses

Failure, Success

Defined Under Namespace

Classes: Failure, Success

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorObject (readonly)

Reason for failure



29
30
31
# File 'lib/tty/option/result.rb', line 29

def error
  @error
end

#valueObject (readonly)

Wrapped value



24
25
26
# File 'lib/tty/option/result.rb', line 24

def value
  @value
end

Class Method Details

.failure(value) ⇒ Object

Wrap a value in a failure monad



17
18
19
# File 'lib/tty/option/result.rb', line 17

def self.failure(value)
  Failure.new(value)
end

.success(value) ⇒ Object

Wrap a value in a success monad



10
11
12
# File 'lib/tty/option/result.rb', line 10

def self.success(value)
  Success.new(value)
end

Instance Method Details

#failure?Boolean

Check whether or not a result is a failure class

Returns:

  • (Boolean)


45
46
47
# File 'lib/tty/option/result.rb', line 45

def failure?
  is_a?(Failure)
end

#success?Boolean

Check whether or not a result is a success monad

Returns:

  • (Boolean)


36
37
38
# File 'lib/tty/option/result.rb', line 36

def success?
  is_a?(Success)
end