Class: Fear::Failure
Constant Summary collapse
- EXTRACTOR =
proc do |try| if Fear::Failure === try Fear.some([try.exception]) else Fear.none end end
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#===(other) ⇒ Boolean
Used in case statement.
- #failure? ⇒ true
-
#flatten ⇒ Failure
Self.
- #get ⇒ Object
-
#initialize(exception) ⇒ Failure
constructor
A new instance of Failure.
- #inspect ⇒ String (also: #to_s)
-
#or_else(*args) ⇒ Try
Of calling block.
- #recover {|| ... } ⇒ Fear::Try
- #recover_with {|| ... } ⇒ Fear::Try
-
#select ⇒ Failure
Self.
- #success? ⇒ Boolean
- #to_either ⇒ Left
Methods included from Try
#any?, #each, #flat_map, #get_or_else, #include?, #map, #match, matcher, #to_option
Constructor Details
#initialize(exception) ⇒ Failure
Returns a new instance of Failure.
15 16 17 |
# File 'lib/fear/failure.rb', line 15 def initialize(exception) @exception = exception end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
19 20 21 |
# File 'lib/fear/failure.rb', line 19 def exception @exception end |
Instance Method Details
#==(other) ⇒ Boolean
82 83 84 |
# File 'lib/fear/failure.rb', line 82 def ==(other) other.is_a?(Failure) && exception == other.exception end |
#===(other) ⇒ Boolean
Used in case statement
89 90 91 92 93 94 95 |
# File 'lib/fear/failure.rb', line 89 def ===(other) if other.is_a?(Failure) exception === other.exception else super end end |
#failure? ⇒ true
27 28 29 |
# File 'lib/fear/failure.rb', line 27 def failure? true end |
#flatten ⇒ Failure
Returns self.
44 45 46 |
# File 'lib/fear/failure.rb', line 44 def flatten self end |
#get ⇒ Object
32 33 34 |
# File 'lib/fear/failure.rb', line 32 def get raise exception end |
#inspect ⇒ String Also known as: to_s
98 99 100 |
# File 'lib/fear/failure.rb', line 98 def inspect "#<Fear::Failure exception=#{exception.inspect}>" end |
#or_else(*args) ⇒ Try
Returns of calling block.
37 38 39 40 41 |
# File 'lib/fear/failure.rb', line 37 def or_else(*args) super rescue StandardError => error Failure.new(error) end |
#recover {|| ... } ⇒ Fear::Try
67 68 69 70 71 72 73 |
# File 'lib/fear/failure.rb', line 67 def recover Fear.matcher { |m| yield(m) } .and_then { |v| Success.new(v) } .call_or_else(exception) { self } rescue StandardError => error Failure.new(error) end |
#recover_with {|| ... } ⇒ Fear::Try
56 57 58 59 60 61 62 |
# File 'lib/fear/failure.rb', line 56 def recover_with Fear.matcher { |m| yield(m) } .and_then { |result| result.tap { Utils.assert_type!(result, Success, Failure) } } .call_or_else(exception) { self } rescue StandardError => error Failure.new(error) end |
#success? ⇒ Boolean
22 23 24 |
# File 'lib/fear/failure.rb', line 22 def success? false end |