Module: Mangrove::Result Abstract
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Kernel
- Defined in:
- lib/mangrove/result.rb,
lib/mangrove/result/control_signal.rb
Overview
This module is abstract.
Subclasses must implement the ‘abstract` methods below.
Result is a type that represents either success (‘Ok`) or failure (`Err`).
Defined Under Namespace
Classes: ControlSignal, Err, Ok
Constant Summary collapse
- OkType =
type_member
- ErrType =
type_member
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean abstract
- #err? ⇒ Boolean abstract
- #expect!(message) ⇒ OkType abstract
- #expect_with!(&block) ⇒ OkType abstract
- #map_err(&block) ⇒ Result[OkType, ErrType] abstract
- #map_ok(&block) ⇒ Result[OkType, ErrType] abstract
- #ok? ⇒ Boolean abstract
- #unwrap! ⇒ OkType abstract
Class Method Details
.from_results(results) ⇒ Result[OkType, ErrType]
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mangrove/result.rb', line 53 def from_results(results) errs = results.filter(&:err?) if errs.empty? # This is safe as errs is empty. Result::Ok.new(results.map { |r| T.cast(r, Result::Ok[OkType, ErrType]).ok_inner }) else # This is safe as errs is results where err? is true Result::Err.new(errs.map { |r| T.cast(r, Result::Err[OkType, ErrType]).err_inner }) end end |
Instance Method Details
#==(other) ⇒ Boolean
This method is abstract.
22 |
# File 'lib/mangrove/result.rb', line 22 def ==(other); end |
#err? ⇒ Boolean
This method is abstract.
28 |
# File 'lib/mangrove/result.rb', line 28 def err?; end |
#expect!(message) ⇒ OkType
This method is abstract.
34 |
# File 'lib/mangrove/result.rb', line 34 def expect!(); end |
#expect_with!(&block) ⇒ OkType
This method is abstract.
37 |
# File 'lib/mangrove/result.rb', line 37 def expect_with!(&block); end |
#map_err(&block) ⇒ Result[OkType, ErrType]
This method is abstract.
43 |
# File 'lib/mangrove/result.rb', line 43 def map_err(&block); end |
#map_ok(&block) ⇒ Result[OkType, ErrType]
This method is abstract.
40 |
# File 'lib/mangrove/result.rb', line 40 def map_ok(&block); end |
#ok? ⇒ Boolean
This method is abstract.
25 |
# File 'lib/mangrove/result.rb', line 25 def ok?; end |
#unwrap! ⇒ OkType
This method is abstract.
31 |
# File 'lib/mangrove/result.rb', line 31 def unwrap!; end |