Module: Mayak::Monads::Try::Mixin
- Extended by:
- T::Sig
- Includes:
- Kernel
- Defined in:
- lib/mayak/monads/try.rb
Instance Method Summary collapse
- #check_try!(value, error, &blk) ⇒ Object
- #do_try!(value) ⇒ Object
- #for_try(&blk) ⇒ Object
- #guard_try!(error, &blk) ⇒ Object
- #Try(*exception_classes, &blk) ⇒ Object
Instance Method Details
#check_try!(value, error, &blk) ⇒ Object
622 623 624 |
# File 'lib/mayak/monads/try.rb', line 622 def check_try!(value, error, &blk) do_try!(Mayak::Monads::Try.check(value, error, &blk)) end |
#do_try!(value) ⇒ Object
603 604 605 606 607 608 609 610 611 612 |
# File 'lib/mayak/monads/try.rb', line 603 def do_try!(value) case value when Mayak::Monads::Try::Success value.success when Mayak::Monads::Try::Failure raise Halt[T.type_parameter(:Value)].new(value) else T.absurd(value) end end |
#for_try(&blk) ⇒ Object
591 592 593 594 595 596 |
# File 'lib/mayak/monads/try.rb', line 591 def for_try(&blk) result = blk.call Mayak::Monads::Try::Success[T.type_parameter(:Value)].new(result) rescue Halt => e e.result end |
#guard_try!(error, &blk) ⇒ Object
627 628 629 |
# File 'lib/mayak/monads/try.rb', line 627 def guard_try!(error, &blk) do_try!(Mayak::Monads::Try.guard(error, &blk)) end |
#Try(*exception_classes, &blk) ⇒ Object
577 578 579 580 581 582 583 584 |
# File 'lib/mayak/monads/try.rb', line 577 def Try(*exception_classes, &blk) exception_classes = [StandardError] if exception_classes.empty? begin Mayak::Monads::Try::Success[T.type_parameter(:Value)].new(blk.call) rescue *exception_classes => e Mayak::Monads::Try::Failure[T.type_parameter(:Value)].new(T.unsafe(e)) end end |