Class: Funcify::Monad
- Inherits:
-
Object
- Object
- Funcify::Monad
- Extended by:
- Dry::Monads::Result::Mixin
- Defined in:
- lib/funcify/monad.rb
Class Method Summary collapse
-
.failure ⇒ Object
> failure.(:error) => Failure(:error).
-
.lift ⇒ Object
operates with a Result and a Try monad > lift.(Success(:ok)) => :ok.
- .maybe_failure ⇒ Object
- .maybe_value ⇒ Object
- .maybe_value_fail? ⇒ Boolean
- .maybe_value_ok? ⇒ Boolean
-
.success ⇒ Object
> success.(:ok) => Success(:ok).
- .try_maybe_failure ⇒ Object
Class Method Details
.failure ⇒ Object
> failure.(:error) => Failure(:error)
18 19 20 |
# File 'lib/funcify/monad.rb', line 18 def failure -> value { Failure(value) } end |
.lift ⇒ Object
operates with a Result and a Try monad > lift.(Success(:ok)) => :ok
11 12 13 14 15 |
# File 'lib/funcify/monad.rb', line 11 def lift -> value { maybe_value_ok?.(value) ? maybe_value.(value) : try_maybe_failure.(value) } end |
.maybe_failure ⇒ Object
39 40 41 |
# File 'lib/funcify/monad.rb', line 39 def maybe_failure -> v { v.failure } end |
.maybe_value ⇒ Object
35 36 37 |
# File 'lib/funcify/monad.rb', line 35 def maybe_value ->(v) { v.value_or } end |
.maybe_value_fail? ⇒ Boolean
31 32 33 |
# File 'lib/funcify/monad.rb', line 31 def maybe_value_fail? -> m { m.respond_to?(:failure?) && m.failure? } end |
.maybe_value_ok? ⇒ Boolean
27 28 29 |
# File 'lib/funcify/monad.rb', line 27 def maybe_value_ok? -> m { m.respond_to?(:success?) && m.success? } end |
.success ⇒ Object
> success.(:ok) => Success(:ok)
23 24 25 |
# File 'lib/funcify/monad.rb', line 23 def success -> value { Success(value) } end |
.try_maybe_failure ⇒ Object
43 44 45 46 47 |
# File 'lib/funcify/monad.rb', line 43 def try_maybe_failure -> v { v.respond_to?(:failure) ? v.failure : v.exception } end |