Class: Mangrove::Option::Some

Inherits:
Object
  • Object
show all
Extended by:
T::Generic, T::Helpers, T::Sig
Includes:
Mangrove::Option
Defined in:
lib/mangrove/option.rb

Overview

Option::Some

Constant Summary collapse

InnerType =
type_member

Instance Method Summary collapse

Methods included from Mangrove::Option

from_nilable

Constructor Details

#initialize(inner) ⇒ void

Parameters:



46
47
48
# File 'lib/mangrove/option.rb', line 46

def initialize(inner)
  @inner = T.let(inner, InnerType)
end

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mangrove/option.rb', line 51

def ==(other)
  case other
  when Option::Some
    other.instance_variable_get(:@inner) == @inner
  when Option::None
    false
  else # rubocop:disable Lint/DuplicateBranch
    # Because == is defined on BasicObject, we can't be sure that `other` is an Option
    false
  end
end

#expect!(_message) ⇒ InnerType

Parameters:

  • _message (String)

Returns:



79
80
81
# File 'lib/mangrove/option.rb', line 79

def expect!(_message)
  @inner
end

#expect_with!(&_block) ⇒ InnerType

Parameters:

  • _block (T.proc.returns(T.untyped))

Returns:



84
85
86
# File 'lib/mangrove/option.rb', line 84

def expect_with!(&_block)
  @inner
end

#map(&block) ⇒ ::Mangrove::Option[T.type_parameter(:NewInnerType)]

Parameters:

  • block (T.proc.params(inner: InnerType).returns(Option[T.type_parameter(:NewInnerType)]))

Returns:



95
96
97
# File 'lib/mangrove/option.rb', line 95

def map(&block)
  block.call(@inner)
end

#none?Boolean

Returns:

  • (Boolean)


92
# File 'lib/mangrove/option.rb', line 92

def none? = false

#or(_default) ⇒ Option[InnerType]

Parameters:

Returns:



100
101
102
# File 'lib/mangrove/option.rb', line 100

def or(_default)
  self
end

#some?Boolean

Returns:

  • (Boolean)


89
# File 'lib/mangrove/option.rb', line 89

def some? = true

#transpose(_err) ⇒ Mangrove::Result[InnerType, T.type_parameter(:ErrType)]

Parameters:

  • _err (T.type_parameter(:ErrType))

Returns:



105
106
107
# File 'lib/mangrove/option.rb', line 105

def transpose(_err)
  Result::Ok.new(@inner)
end

#unwrapInnerType

Returns:



64
65
66
# File 'lib/mangrove/option.rb', line 64

def unwrap
  @inner
end

#unwrap!InnerType

Returns:



74
75
76
# File 'lib/mangrove/option.rb', line 74

def unwrap!
  @inner
end

#unwrap_or(_default) ⇒ InnerType

Parameters:

Returns:



69
70
71
# File 'lib/mangrove/option.rb', line 69

def unwrap_or(_default)
  @inner
end