Class: Mayak::Monads::Result::Failure
- Inherits:
-
Object
- Object
- Mayak::Monads::Result::Failure
show all
- Extended by:
- T::Generic, T::Helpers, T::Sig
- Includes:
- Mayak::Monads::Result
- Defined in:
- lib/mayak/monads/result.rb
Constant Summary
collapse
- FailureType =
type_member
- SuccessType =
type_member
Instance Method Summary
collapse
#==, #as, #failure_as, sequence
Constructor Details
#initialize(value) ⇒ Failure
Returns a new instance of Failure.
436
437
438
|
# File 'lib/mayak/monads/result.rb', line 436
def initialize(value)
@failure_value = T.let(value, FailureType)
end
|
Instance Method Details
#either(failure_branch, success_branch) ⇒ Object
542
543
544
|
# File 'lib/mayak/monads/result.rb', line 542
def either(failure_branch, success_branch)
failure_branch.call(@failure_value)
end
|
#failure ⇒ Object
479
480
481
|
# File 'lib/mayak/monads/result.rb', line 479
def failure
@failure_value
end
|
#failure? ⇒ Boolean
489
490
491
|
# File 'lib/mayak/monads/result.rb', line 489
def failure?
true
end
|
#failure_or(value) ⇒ Object
509
510
511
|
# File 'lib/mayak/monads/result.rb', line 509
def failure_or(value)
@failure_value
end
|
#filter_or(error, &blk) ⇒ Object
474
475
476
|
# File 'lib/mayak/monads/result.rb', line 474
def filter_or(error, &blk)
self
end
|
#flat_map(&blk) ⇒ Object
461
462
463
464
465
466
|
# File 'lib/mayak/monads/result.rb', line 461
def flat_map(&blk)
T.cast(
self,
Mayak::Monads::Result[FailureType, T.type_parameter(:NewSuccess)]
)
end
|
#flat_map_failure(&blk) ⇒ Object
577
578
579
|
# File 'lib/mayak/monads/result.rb', line 577
def flat_map_failure(&blk)
blk.call(@failure_value)
end
|
#map(&blk) ⇒ Object
446
447
448
449
450
451
|
# File 'lib/mayak/monads/result.rb', line 446
def map(&blk)
T.cast(
self,
Mayak::Monads::Result[FailureType, T.type_parameter(:NewSuccess)]
)
end
|
#map_failure(&blk) ⇒ Object
564
565
566
|
# File 'lib/mayak/monads/result.rb', line 564
def map_failure(&blk)
Mayak::Monads::Result::Failure[T.type_parameter(:NewFailure), SuccessType].new(blk.call(@failure_value))
end
|
#recover_with(&blk) ⇒ Object
#recover_with_result(&blk) ⇒ Object
613
614
615
|
# File 'lib/mayak/monads/result.rb', line 613
def recover_with_result(&blk)
blk.call(@failure_value)
end
|
#success? ⇒ Boolean
484
485
486
|
# File 'lib/mayak/monads/result.rb', line 484
def success?
false
end
|
#success_or(value) ⇒ Object
499
500
501
|
# File 'lib/mayak/monads/result.rb', line 499
def success_or(value)
value
end
|
#tee(&blk) ⇒ Object
551
552
553
|
# File 'lib/mayak/monads/result.rb', line 551
def tee(&blk)
self
end
|
#to_maybe ⇒ Object
528
529
530
|
# File 'lib/mayak/monads/result.rb', line 528
def to_maybe
Mayak::Monads::Maybe::None.new
end
|
#to_try(&blk) ⇒ Object
523
524
525
|
# File 'lib/mayak/monads/result.rb', line 523
def to_try(&blk)
Mayak::Monads::Try::Failure.new(blk.call(@failure_value))
end
|