Module: R::Result Abstract
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Kernel
- Defined in:
- lib/r/result.rb
Overview
Constant Summary collapse
- OkType =
The type of the success value.
type_member(:out)
- ErrType =
The type of the error value.
type_member(:out)
Instance Method Summary collapse
- #==(other) ⇒ Boolean abstract
- #and(res) ⇒ Result[T.type_parameter(:U), T.any(ErrType, T.type_parameter(:F))] abstract
- #and_then(&blk) ⇒ Result[T.type_parameter(:U), T.any(ErrType, T.type_parameter(:F))] abstract
- #err ⇒ ErrType? abstract
-
#err? ⇒ Boolean
abstract
Returns
true
if the result is Err. -
#err_and?(&blk) ⇒ Boolean
abstract
Returns
true
if the result is Err and the value inside of it matches a predicate. -
#expect!(msg) ⇒ OkType
abstract
Returns the contained Ok value, or raises an UnwrapFailedError if the result is Err.
-
#expect_err!(msg) ⇒ ErrType
abstract
Returns the contained Err value, or raises an UnwrapFailedError if the result is Ok.
-
#inspect ⇒ String
abstract
Returns a string representation of
self
. - #map(&blk) ⇒ Result[T.type_parameter(:U), ErrType] abstract
- #map_err(&blk) ⇒ Result[OkType, T.type_parameter(:F)] abstract
- #map_or(default, &blk) ⇒ T.type_parameter(:U) abstract
- #map_or_else(default, &blk) ⇒ T.type_parameter(:U) abstract
- #ok ⇒ OkType? abstract
-
#ok? ⇒ Boolean
abstract
Returns
true
if the result is Ok. -
#ok_and?(&blk) ⇒ Boolean
abstract
Returns
true
if the result is Ok and the value inside of it matches a predicate. -
#on_err(&blk) ⇒ T.self_type
abstract
Calls the provided block with the contained error (if Err).
-
#on_ok(&blk) ⇒ T.self_type
abstract
Calls the provided block with the contained value (if Ok).
- #or(res) ⇒ Result[T.any(OkType, T.type_parameter(:U)), T.type_parameter(:F)] abstract
- #or_else(&blk) ⇒ Result[T.any(OkType, T.type_parameter(:U)), T.type_parameter(:F)] abstract
- #try?(&blk) ⇒ OkType abstract
-
#unwrap! ⇒ OkType
abstract
Returns the contained Ok value, or raises an UnwrapFailedError if the result is Err.
-
#unwrap_err! ⇒ ErrType
abstract
Returns the contained Err value, or raises an UnwrapFailedError if the result is Ok.
-
#unwrap_or(default) ⇒ OkType, T.type_parameter(:DefaultType)
abstract
Returns the contained Ok value or a provided default.
-
#unwrap_or_else(&blk) ⇒ OkType, T.type_parameter(:DefaultType)
abstract
Returns the contained Ok value or computes it from a closure.
Instance Method Details
#==(other) ⇒ Boolean
48 |
# File 'lib/r/result.rb', line 48 def ==(other); end |
#and(res) ⇒ Result[T.type_parameter(:U), T.any(ErrType, T.type_parameter(:F))]
417 |
# File 'lib/r/result.rb', line 417 def and(res); end |
#and_then(&blk) ⇒ Result[T.type_parameter(:U), T.any(ErrType, T.type_parameter(:F))]
446 |
# File 'lib/r/result.rb', line 446 def and_then(&blk); end |
#err ⇒ ErrType?
152 |
# File 'lib/r/result.rb', line 152 def err; end |
#err? ⇒ Boolean
Returns true
if the result is Err.
107 |
# File 'lib/r/result.rb', line 107 def err?; end |
#err_and?(&blk) ⇒ Boolean
Returns true
if the result is Err and the value inside of it matches a predicate.
124 |
# File 'lib/r/result.rb', line 124 def err_and?(&blk); end |
#expect!(msg) ⇒ OkType
Returns the contained Ok value, or raises an UnwrapFailedError if the result is Err.
Because this function may raise an exception, its use is generally discouraged. Instead, prefer to use pattern matching and #ok, or call #unwrap_or or #unwrap_or_else.
330 |
# File 'lib/r/result.rb', line 330 def expect!(msg); end |
#expect_err!(msg) ⇒ ErrType
Returns the contained Err value, or raises an UnwrapFailedError if the result is Ok.
368 |
# File 'lib/r/result.rb', line 368 def expect_err!(msg); end |
#inspect ⇒ String
Returns a string representation of self
.
62 |
# File 'lib/r/result.rb', line 62 def inspect; end |
#map(&blk) ⇒ Result[T.type_parameter(:U), ErrType]
192 |
# File 'lib/r/result.rb', line 192 def map(&blk); end |
#map_err(&blk) ⇒ Result[OkType, T.type_parameter(:F)]
275 |
# File 'lib/r/result.rb', line 275 def map_err(&blk); end |
#map_or(default, &blk) ⇒ T.type_parameter(:U)
Returns the provided default (if Err), or applies a function to the contained value (if Ok).
Arguments passed to #map_or are eagerly evaluated; if you are passing the result of a function call, it is recommended to use #map_or_else, which is lazily evaluated.
217 |
# File 'lib/r/result.rb', line 217 def map_or(default, &blk); end |
#map_or_else(default, &blk) ⇒ T.type_parameter(:U)
244 |
# File 'lib/r/result.rb', line 244 def map_or_else(default, &blk); end |
#ok ⇒ OkType?
138 |
# File 'lib/r/result.rb', line 138 def ok; end |
#ok? ⇒ Boolean
Returns true
if the result is Ok.
76 |
# File 'lib/r/result.rb', line 76 def ok?; end |
#ok_and?(&blk) ⇒ Boolean
Returns true
if the result is Ok and the value inside of it matches a predicate.
93 |
# File 'lib/r/result.rb', line 93 def ok_and?(&blk); end |
#on_err(&blk) ⇒ T.self_type
309 |
# File 'lib/r/result.rb', line 309 def on_err(&blk); end |
#on_ok(&blk) ⇒ T.self_type
292 |
# File 'lib/r/result.rb', line 292 def on_ok(&blk); end |
#or(res) ⇒ Result[T.any(OkType, T.type_parameter(:U)), T.type_parameter(:F)]
478 |
# File 'lib/r/result.rb', line 478 def or(res); end |
#or_else(&blk) ⇒ Result[T.any(OkType, T.type_parameter(:U)), T.type_parameter(:F)]
512 |
# File 'lib/r/result.rb', line 512 def or_else(&blk); end |
#try?(&blk) ⇒ OkType
Returns the contained Ok value or calls the block with the Err value.
This method is similar to #unwrap_or_else, but in case of an Err value, the block must short-circuit by
either calling return
(which will return from the enclosing method) or raising an exception.
This is useful to make error handling less tedious when dealing with many methods returning results.
582 |
# File 'lib/r/result.rb', line 582 def try?(&blk); end |
#unwrap! ⇒ OkType
Returns the contained Ok value, or raises an UnwrapFailedError if the result is Err.
Because this function may raise an exception, its use is generally discouraged. Instead, prefer to use pattern matching and #ok, or call #unwrap_or or #unwrap_or_else.
350 |
# File 'lib/r/result.rb', line 350 def unwrap!; end |
#unwrap_err! ⇒ ErrType
Returns the contained Err value, or raises an UnwrapFailedError if the result is Ok.
385 |
# File 'lib/r/result.rb', line 385 def unwrap_err!; end |
#unwrap_or(default) ⇒ OkType, T.type_parameter(:DefaultType)
Returns the contained Ok value or a provided default.
Arguments passed to unwrap_or
are eagerly evaluated; if you are passing the result of a function call, it is
recommended to use #unwrap_or_else, which is lazily evaluated.
536 |
# File 'lib/r/result.rb', line 536 def unwrap_or(default); end |