Class: Mangrove::Option::None

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

Overview

Option::None

Constant Summary collapse

InnerType =
type_member

Instance Method Summary collapse

Methods included from Mangrove::Option

from_nilable

Instance Method Details

#==(other) ⇒ Boolean

Parameters:

  • other (BasicObject)

Returns:

  • (Boolean)


126
127
128
129
130
131
132
133
134
135
136
# File 'lib/mangrove/option.rb', line 126

def ==(other)
  case other
  when Option::Some
    false
  when Option::None
    true
  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:

Raises:



149
150
151
# File 'lib/mangrove/option.rb', line 149

def expect!(message)
  raise Option::ControlSignal, message
end

#expect_with!(&block) ⇒ InnerType

Parameters:

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

Returns:

Raises:



154
155
156
# File 'lib/mangrove/option.rb', line 154

def expect_with!(&block)
  raise Option::ControlSignal, block.call
end

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

Parameters:

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

Returns:

  • (Option[T.type_parameter(:NewInnerType)])


165
166
167
# File 'lib/mangrove/option.rb', line 165

def map(&_block)
  T.cast(self, Option[T.type_parameter(:NewInnerType)])
end

#none?Boolean

Returns:

  • (Boolean)


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

def none? = true

#or(default) ⇒ Option[InnerType]

Parameters:

Returns:



170
171
172
# File 'lib/mangrove/option.rb', line 170

def or(default)
  default
end

#some?Boolean

Returns:

  • (Boolean)


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

def some? = false

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

Parameters:

  • err (T.type_parameter(:ErrType))

Returns:



175
176
177
# File 'lib/mangrove/option.rb', line 175

def transpose(err)
  Result::Err.new(err)
end

#unwrap!InnerType

Returns:

Raises:



144
145
146
# File 'lib/mangrove/option.rb', line 144

def unwrap!
  raise Option::ControlSignal, "called `Option#unwrap!` on an `None` value: #{self}"
end

#unwrap_or(default) ⇒ InnerType

Parameters:

Returns:



139
140
141
# File 'lib/mangrove/option.rb', line 139

def unwrap_or(default)
  default
end