Class: Mangrove::Option::Some
- Inherits:
-
Object
- Object
- Mangrove::Option::Some
- 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
- #==(other) ⇒ Boolean
- #expect!(_message) ⇒ InnerType
- #expect_with!(&_block) ⇒ InnerType
- #initialize(inner) ⇒ void constructor
- #map(&block) ⇒ ::Mangrove::Option[T.type_parameter(:NewInnerType)]
- #none? ⇒ Boolean
- #or(_default) ⇒ Option[InnerType]
- #some? ⇒ Boolean
- #transpose(_err) ⇒ Mangrove::Result[InnerType, T.type_parameter(:ErrType)]
- #unwrap ⇒ InnerType
- #unwrap! ⇒ InnerType
- #unwrap_or(_default) ⇒ InnerType
Methods included from Mangrove::Option
Constructor Details
#initialize(inner) ⇒ void
46 47 48 |
# File 'lib/mangrove/option.rb', line 46 def initialize(inner) @inner = T.let(inner, InnerType) end |
Instance Method Details
#==(other) ⇒ 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
79 80 81 |
# File 'lib/mangrove/option.rb', line 79 def expect!() @inner end |
#expect_with!(&_block) ⇒ InnerType
84 85 86 |
# File 'lib/mangrove/option.rb', line 84 def expect_with!(&_block) @inner end |
#map(&block) ⇒ ::Mangrove::Option[T.type_parameter(:NewInnerType)]
95 96 97 |
# File 'lib/mangrove/option.rb', line 95 def map(&block) block.call(@inner) end |
#none? ⇒ Boolean
92 |
# File 'lib/mangrove/option.rb', line 92 def none? = false |
#or(_default) ⇒ Option[InnerType]
100 101 102 |
# File 'lib/mangrove/option.rb', line 100 def or(_default) self end |
#some? ⇒ Boolean
89 |
# File 'lib/mangrove/option.rb', line 89 def some? = true |
#transpose(_err) ⇒ Mangrove::Result[InnerType, T.type_parameter(:ErrType)]
105 106 107 |
# File 'lib/mangrove/option.rb', line 105 def transpose(_err) Result::Ok.new(@inner) end |
#unwrap_or(_default) ⇒ InnerType
69 70 71 |
# File 'lib/mangrove/option.rb', line 69 def unwrap_or(_default) @inner end |