Class: Mangrove::Result::Err
- Inherits:
-
Object
- Object
- Mangrove::Result::Err
- 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
- #err_inner ⇒ ErrType
- #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)]
- #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
- #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
238 239 240 |
# File 'lib/mangrove/result.rb', line 238 def initialize(inner) @inner = inner end |
Instance Method Details
#==(other) ⇒ Boolean
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/mangrove/result.rb', line 243 def ==(other) case other when Result::Ok false when Result::Err other.instance_variable_get(:@inner) == @inner else false end end |
#and(_other) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
312 313 314 |
# File 'lib/mangrove/result.rb', line 312 def and(_other) T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType]) end |
#and_then(&_block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
317 318 319 |
# File 'lib/mangrove/result.rb', line 317 def and_then(&_block) T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType]) end |
#and_then_wt(_t_new_ok, &_block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
322 323 324 |
# File 'lib/mangrove/result.rb', line 322 def and_then_wt(_t_new_ok, &_block) T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType]) end |
#err? ⇒ Boolean
278 |
# File 'lib/mangrove/result.rb', line 278 def err? = true |
#expect!(message) ⇒ OkType
265 266 267 |
# File 'lib/mangrove/result.rb', line 265 def expect!() raise Result::ControlSignal, end |
#expect_with!(&block) ⇒ OkType
270 271 272 |
# File 'lib/mangrove/result.rb', line 270 def expect_with!(&block) raise Result::ControlSignal, block.call end |
#map(&block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
281 282 283 |
# File 'lib/mangrove/result.rb', line 281 def map(&block) block.call(self) end |
#map_err(&block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
302 303 304 |
# File 'lib/mangrove/result.rb', line 302 def map_err(&block) Result::Err[OkType, T.type_parameter(:NewErrType)].new(block.call(@inner)) end |
#map_err_wt(_t_new_err, &block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
307 308 309 |
# File 'lib/mangrove/result.rb', line 307 def map_err_wt(_t_new_err, &block) Result::Err[OkType, T.type_parameter(:NewErrType)].new(block.call(@inner)) end |
#map_ok(&_block) ⇒ Result[T.type_parameter(:NewOkType), ErrType]
291 292 293 |
# File 'lib/mangrove/result.rb', line 291 def map_ok(&_block) T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType]) 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.
297 298 299 |
# File 'lib/mangrove/result.rb', line 297 def map_ok_wt(_t_new_ok, &_block) T.cast(self, Result::Err[T.type_parameter(:NewOkType), ErrType]) end |
#map_wt(_t_new_ok, _t_new_err, &block) ⇒ Result[T.type_parameter(:NewOkType), T.type_parameter(:NewErrType)]
286 287 288 |
# File 'lib/mangrove/result.rb', line 286 def map_wt(_t_new_ok, _t_new_err, &block) block.call(self) end |
#ok? ⇒ Boolean
275 |
# File 'lib/mangrove/result.rb', line 275 def ok? = false |
#or(other) ⇒ Result[OkType, ErrType]
327 328 329 |
# File 'lib/mangrove/result.rb', line 327 def or(other) other end |
#or_else(&block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
332 333 334 |
# File 'lib/mangrove/result.rb', line 332 def or_else(&block) block.call(@inner) end |
#or_else_wt(_t_new_err, &block) ⇒ Result[OkType, T.type_parameter(:NewErrType)]
337 338 339 |
# File 'lib/mangrove/result.rb', line 337 def or_else_wt(_t_new_err, &block) block.call(@inner) end |
#to_s ⇒ String
342 343 344 |
# File 'lib/mangrove/result.rb', line 342 def to_s "#{super}: inner=`#{@inner}`" end |
#unwrap! ⇒ OkType
260 261 262 |
# File 'lib/mangrove/result.rb', line 260 def unwrap! raise Result::ControlSignal, @inner end |