Module: Mayak::Monads::Maybe::Mixin
- Extended by:
- T::Sig
- Includes:
- Kernel
- Defined in:
- lib/mayak/monads/maybe.rb
Instance Method Summary collapse
- #check_maybe!(value, &blk) ⇒ Object
- #do_maybe!(value) ⇒ Object
- #for_maybe(&blk) ⇒ Object
- #guard_maybe!(&blk) ⇒ Object
- #Maybe(value) ⇒ Object
- #None ⇒ Object
Instance Method Details
#check_maybe!(value, &blk) ⇒ Object
480 481 482 |
# File 'lib/mayak/monads/maybe.rb', line 480 def check_maybe!(value, &blk) do_maybe!(Mayak::Monads::Maybe.check(value, &blk)) end |
#do_maybe!(value) ⇒ Object
464 465 466 467 468 469 470 471 472 473 |
# File 'lib/mayak/monads/maybe.rb', line 464 def do_maybe!(value) case value when Mayak::Monads::Maybe::Some value.value when Mayak::Monads::Maybe::None raise Halt[T.type_parameter(:Value)].new(value) else T.absurd(value) end end |
#for_maybe(&blk) ⇒ Object
452 453 454 455 456 457 |
# File 'lib/mayak/monads/maybe.rb', line 452 def for_maybe(&blk) result = blk.call Mayak::Monads::Maybe::Some[T.type_parameter(:Value)].new(result) rescue Halt => e e.result end |
#guard_maybe!(&blk) ⇒ Object
485 486 487 |
# File 'lib/mayak/monads/maybe.rb', line 485 def guard_maybe!(&blk) do_maybe!(Mayak::Monads::Maybe.guard(&blk)) end |