Class: Monads::Result
- Inherits:
-
Object
- Object
- Monads::Result
- Includes:
- Monad
- Defined in:
- lib/ruby-monads/result.rb
Constant Summary collapse
- FAILURE_TRIGGER =
StandardError
Class Method Summary collapse
-
.unit(value) ⇒ Object
- unit
-
a -> M a.
Instance Method Summary collapse
-
#bind(&block) ⇒ Object
- bind
-
(a -> M b) -> M a -> M b.
-
#unwrap(default_value = @value) ⇒ Object
- unwrap
-
a -> M a -> a.
Methods included from Monad
#fmap, included, #initialize, #join, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Monads::Monad
Class Method Details
Instance Method Details
#bind(&block) ⇒ Object
- bind
-
(a -> M b) -> M a -> M b
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby-monads/result.rb', line 19 def bind(&block) return self if is_a?(Failure) begin ensure_monadic_result(&block).call rescue FAILURE_TRIGGER => error Failure.new(error) end end |
#unwrap(default_value = @value) ⇒ Object
- unwrap
-
a -> M a -> a
30 31 32 |
# File 'lib/ruby-monads/result.rb', line 30 def unwrap(default_value = @value) is_a?(Failure) ? default_value : @value end |