Class: Muina::Maybe Abstract
- Inherits:
-
Object
- Object
- Muina::Maybe
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Defined in:
- lib/muina/maybe.rb,
lib/muina/maybe/none.rb,
lib/muina/maybe/some.rb
Overview
Defined Under Namespace
Constant Summary collapse
- UnwrappingError =
Raised when trying to unwrap a None value
Class.new(Error)
- Elem =
type_member
- ElemT =
type_template { { upper: Object } }
Class Method Summary collapse
-
.none ⇒ None
Returns a None, a safer alternative to
nil
. -
.return(value) ⇒ Some<Elem>
(also: some)
Returns a Some wrapping the provided value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns
true
if both instances are of the same variant, and the contained values are equal in the case of Some. -
#and_then {|value| ... } ⇒ self
Runs the provided block only if instance is of the Some variant, yielding the contained value.
- #bind {|value| ... } ⇒ Maybe
- #bind_none { ... } ⇒ Maybe
- #map {|value| ... } ⇒ Maybe<yield>, None
- #map_none { ... } ⇒ Maybe<yield>, self
- #none? ⇒ true, false
-
#or_else { ... } ⇒ self
Runs the provided block only if instance is of the None variant, yielding no value to the block.
- #some? ⇒ true, false
-
#value! ⇒ Elem
Returns the contained value if instance is of the Some variant, or raises UnwrappingError if it is of the None variant.
- #value_or(default) ⇒ Elem, Object
- #value_or_nil ⇒ Elem?
- #value_or_yield(&blk) ⇒ Elem, yield
Class Method Details
Instance Method Details
#==(other) ⇒ Boolean
Returns true
if both instances are of the same variant, and the contained values are equal in the case of Some.
196 197 |
# File 'lib/muina/maybe.rb', line 196 def ==(other) end |
#and_then {|value| ... } ⇒ self
Runs the provided block only if instance is of the Some variant, yielding the contained value. Always returns self
.
113 114 |
# File 'lib/muina/maybe.rb', line 113 def and_then(&_blk) end |
#map {|value| ... } ⇒ Maybe<yield>, None
140 141 |
# File 'lib/muina/maybe.rb', line 140 def map(&_blk) end |
#map_none { ... } ⇒ Maybe<yield>, self
155 156 |
# File 'lib/muina/maybe.rb', line 155 def map_none(&blk) end |
#none? ⇒ true, false
59 60 |
# File 'lib/muina/maybe.rb', line 59 def none? end |
#or_else { ... } ⇒ self
Runs the provided block only if instance is of the None variant, yielding no value to the block. Always returns self
.
123 124 |
# File 'lib/muina/maybe.rb', line 123 def or_else(&_blk) end |
#some? ⇒ true, false
50 51 |
# File 'lib/muina/maybe.rb', line 50 def some? end |
#value! ⇒ Elem
Returns the contained value if instance is of the Some variant, or raises UnwrappingError if it is of the None variant.
68 69 |
# File 'lib/muina/maybe.rb', line 68 def value! end |
#value_or(default) ⇒ Elem, Object
82 83 |
# File 'lib/muina/maybe.rb', line 82 def value_or(default) end |