Class: Muina::Maybe::None
- Inherits:
-
Muina::Maybe
- Object
- Muina::Maybe
- Muina::Maybe::None
- Defined in:
- lib/muina/maybe/none.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- Elem =
type_member
- ElemT =
type_template { { upper: Object } }
Constants inherited from Muina::Maybe
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
-
#initialize ⇒ None
constructor
rubocop:disable Lint/MissingSuper.
- #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
Methods inherited from Muina::Maybe
Constructor Details
#initialize ⇒ None
rubocop:disable Lint/MissingSuper
19 20 21 |
# File 'lib/muina/maybe/none.rb', line 19 def initialize # rubocop:disable Lint/MissingSuper freeze end |
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.
124 125 126 |
# File 'lib/muina/maybe/none.rb', line 124 def ==(other) other.instance_of?(self.class) end |
#and_then {|value| ... } ⇒ self
Runs the provided block only if instance is of the Some variant, yielding the contained value. Always returns self
.
67 68 69 |
# File 'lib/muina/maybe/none.rb', line 67 def and_then(&_blk) self end |
#bind {|value| ... } ⇒ Maybe
If instance is of the Some variant, it yields the contained value to the block and it returns the return value of the block; if it is of the Muina::Maybe::None variant, it returns itself.
108 109 110 |
# File 'lib/muina/maybe/none.rb', line 108 def bind(&_blk) self end |
#bind_none { ... } ⇒ Maybe
If instance is of the Muina::Maybe::None variant, it runs the provided block and it returns its return value; if it is of the Some variant, it returns itself.
118 119 120 |
# File 'lib/muina/maybe/none.rb', line 118 def bind_none(&_blk) yield end |
#map {|value| ... } ⇒ Maybe<yield>, None
If instance is of the Some variant, it passes the contained value to the block and returns a new Some instance containing the return value of the block; if instance is of the Muina::Maybe::None variant, it returns itself.
86 87 88 |
# File 'lib/muina/maybe/none.rb', line 86 def map(&_blk) self end |
#map_none { ... } ⇒ Maybe<yield>, self
If instance is of the Some variant, it returns itself; if instance is of the Muina::Maybe::None variant it runs the block and returns a new Some instance containing the return value of the block.
96 97 98 |
# File 'lib/muina/maybe/none.rb', line 96 def map_none(&_blk) Maybe.return yield end |
#none? ⇒ true, false
Returns true
if instance is of the Muina::Maybe::None variant, or false
if it is of the Some variant.
31 32 33 |
# File 'lib/muina/maybe/none.rb', line 31 def none? true end |
#or_else { ... } ⇒ self
Runs the provided block only if instance is of the Muina::Maybe::None variant, yielding no value to the block. Always returns self
.
73 74 75 76 |
# File 'lib/muina/maybe/none.rb', line 73 def or_else(&_blk) yield self end |
#some? ⇒ true, false
Returns true
if instance is of the Some variant, or false
if it is of the Muina::Maybe::None variant.
25 26 27 |
# File 'lib/muina/maybe/none.rb', line 25 def some? false end |
#value! ⇒ Elem
Returns the contained value if instance is of the Some variant, or raises UnwrappingError if it is of the Muina::Maybe::None variant.
37 38 39 |
# File 'lib/muina/maybe/none.rb', line 37 def value! raise UnwrappingError end |
#value_or(default) ⇒ Elem, Object
Returns the contained value if instance is of the Some variant, or the provided default
value if it is of the Muina::Maybe::None variant.
47 48 49 |
# File 'lib/muina/maybe/none.rb', line 47 def value_or(default) default end |
#value_or_nil ⇒ Elem?
Returns the contained value if instance is of the Some variant, or nil
if it is of the Muina::Maybe::None variant.
63 |
# File 'lib/muina/maybe/none.rb', line 63 def value_or_nil; end |
#value_or_yield(&_blk) ⇒ Elem, yield
Returns the contained value if instance is of the Some variant, or runs the provided block and returns its result if it is of the Muina::Maybe::None variant.
57 58 59 |
# File 'lib/muina/maybe/none.rb', line 57 def value_or_yield(&_blk) yield end |