Class: Resonad::Failure

Inherits:
Resonad show all
Defined in:
lib/resonad.rb

Constant Summary

Constants inherited from Resonad

Mixin, NIL_FAILURE, NIL_SUCCESS, VERSION

Constants included from PublicMixin

PublicMixin::Failure, PublicMixin::Success

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resonad

#and_then, #bad?, #failed?, #failure?, #flat_map, #flat_map_error, #if_bad, #if_failed, #if_failure, #if_ok, #if_success, #if_successful, #map, #map_error, #map_value, #ok?, #on_bad, #on_failed, #on_failure, #on_ok, #on_success, #on_successful, #or_else, #otherwise, rescuing_from, #successful?, #when_bad, #when_failed, #when_failure, #when_ok, #when_success, #when_successful

Methods included from PublicMixin

#Failure, #Success, #failure, #success

Constructor Details

#initialize(error) ⇒ Failure

Returns a new instance of Failure.



81
82
83
84
# File 'lib/resonad.rb', line 81

def initialize(error)
  @error = error
  freeze
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



71
72
73
# File 'lib/resonad.rb', line 71

def error
  @error
end

Class Method Details

.[](error = nil) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/resonad.rb', line 73

def self.[](error = nil)
  if nil == error
    NIL_FAILURE
  else
    new(error)
  end
end

Instance Method Details

#deconstructObject



94
95
96
# File 'lib/resonad.rb', line 94

def deconstruct
  [:failure, error]
end

#deconstruct_keys(_) ⇒ Object



98
99
100
# File 'lib/resonad.rb', line 98

def deconstruct_keys(_)
  { error: error }
end

#success?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/resonad.rb', line 86

def success?
  false
end

#valueObject

Raises:



90
91
92
# File 'lib/resonad.rb', line 90

def value
  raise NonExistentValue, "Failure resonads do not have values"
end