Class: Muina::Maybe::None

Inherits:
Muina::Maybe show all
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

UnwrappingError

Instance Method Summary collapse

Methods inherited from Muina::Maybe

none, return

Constructor Details

#initializeNone

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.

Parameters:

Returns:

  • (Boolean)


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.

Yield Parameters:

  • value (Elem)

    the contained value is passed to the block

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.

Yield Parameters:

  • value (Elem)

    the contained value is passed to the block

Yield Returns:

Returns:



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.

Yields:

Yield Returns:

Returns:



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.

Yield Parameters:

  • value (Elem)

    the contained value is passed to the block

Yield Returns:

  • (Object)

Returns:



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.

Yields:

Yield Returns:

  • (Object)

Returns:



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.

Returns:



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.

Yields:

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.

Returns:



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.

Returns:

Raises:



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.

Parameters:

  • default (Object)

    the value to be used if the instance is of the Muina::Maybe::None variant

Returns:



47
48
49
# File 'lib/muina/maybe/none.rb', line 47

def value_or(default)
  default
end

#value_or_nilElem?

Returns the contained value if instance is of the Some variant, or nil if it is of the Muina::Maybe::None variant.

Returns:



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.

Yield Returns:

  • (Object)

Returns:



57
58
59
# File 'lib/muina/maybe/none.rb', line 57

def value_or_yield(&_blk)
  yield
end