Class: Mangrove::Result::Ok
- Inherits:
-
Object
- Object
- Mangrove::Result::Ok
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Mangrove::Result
- Defined in:
- lib/mangrove/result.rb
Constant Summary collapse
- OkType =
type_member
- ErrType =
type_member
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #and(other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
- #and_then(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
- #and_then_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
- #err? ⇒ Boolean
- #expect!(_message) ⇒ OkType
- #expect_with!(&_block) ⇒ OkType
- #initialize(inner) ⇒ void constructor
- #map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
- #map_err(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
-
#map_err_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
Because sorbet deduct types from return values well.
- #map_ok(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
-
#map_ok_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
Because sorbet deduct types from return values well.
- #map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
- #ok? ⇒ Boolean
- #ok_inner ⇒ OkType
- #or(_other) ⇒ Result[OkType, ErrType]
- #or_else(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
- #or_else_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
- #to_s ⇒ String
- #unwrap! ⇒ OkType
Methods included from Mangrove::Result
Constructor Details
#initialize(inner) ⇒ void
117 118 119 |
# File 'lib/mangrove/result.rb', line 117 def initialize(inner) @inner = inner end |
Instance Method Details
#==(other) ⇒ Boolean
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/mangrove/result.rb', line 122 def ==(other) case other when Result::Ok other.instance_variable_get(:@inner) == @inner when Result::Err false else false end end |
#and(other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
192 193 194 |
# File 'lib/mangrove/result.rb', line 192 def and(other) other end |
#and_then(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
197 198 199 |
# File 'lib/mangrove/result.rb', line 197 def and_then(&block) block.call(@inner) end |
#and_then_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
202 203 204 |
# File 'lib/mangrove/result.rb', line 202 def and_then_wt(_t_new_ok, &block) block.call(@inner) end |
#err? ⇒ Boolean
157 |
# File 'lib/mangrove/result.rb', line 157 def err? = false |
#expect!(_message) ⇒ OkType
144 145 146 |
# File 'lib/mangrove/result.rb', line 144 def expect!() @inner end |
#expect_with!(&_block) ⇒ OkType
149 150 151 |
# File 'lib/mangrove/result.rb', line 149 def expect_with!(&_block) @inner end |
#map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
160 161 162 |
# File 'lib/mangrove/result.rb', line 160 def map(&block) block.call(self) end |
#map_err(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
181 182 183 |
# File 'lib/mangrove/result.rb', line 181 def map_err(&_block) T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)]) end |
#map_err_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
Because sorbet deduct types from return values well. This method takes a type of new inner values.
187 188 189 |
# File 'lib/mangrove/result.rb', line 187 def map_err_wt(_t_new_err, &_block) T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)]) end |
#map_ok(&block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
170 171 172 |
# File 'lib/mangrove/result.rb', line 170 def map_ok(&block) Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner)) end |
#map_ok_wt(_t_new_ok, &block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
Because sorbet deduct types from return values well. This method takes a type of new inner values.
176 177 178 |
# File 'lib/mangrove/result.rb', line 176 def map_ok_wt(_t_new_ok, &block) Result::Ok[T.type_parameter(:NewOkType), ErrType].new(block.call(@inner)) end |
#map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
165 166 167 |
# File 'lib/mangrove/result.rb', line 165 def map_wt(_t_new_ok, _t_new_err, &block) block.call(self) end |
#ok? ⇒ Boolean
154 |
# File 'lib/mangrove/result.rb', line 154 def ok? = true |
#or(_other) ⇒ Result[OkType, ErrType]
207 208 209 |
# File 'lib/mangrove/result.rb', line 207 def or(_other) self end |
#or_else(&_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
212 213 214 |
# File 'lib/mangrove/result.rb', line 212 def or_else(&_block) T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)]) end |
#or_else_wt(_t_new_err, &_block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
217 218 219 |
# File 'lib/mangrove/result.rb', line 217 def or_else_wt(_t_new_err, &_block) T.cast(self, Result::Ok[OkType, T.type_parameter(:NewErrType)]) end |
#to_s ⇒ String
222 223 224 |
# File 'lib/mangrove/result.rb', line 222 def to_s "#{super}: inner=`#{@inner}`" end |