class Funcify::Monad

Public Class Methods

failure() click to toggle source

> failure.(:error) => Failure(:error)

# File lib/funcify/monad.rb, line 18
def failure
  -> value { Failure(value) }
end
lift() click to toggle source

operates with a Result and a Try monad > lift.(Success(:ok)) => :ok

# File lib/funcify/monad.rb, line 11
def lift
  -> value {
    maybe_value_ok?.(value) ? maybe_value.(value) : try_maybe_failure.(value)
  }
end
maybe_failure() click to toggle source
# File lib/funcify/monad.rb, line 39
def maybe_failure
  -> v { v.failure }
end
maybe_value() click to toggle source
# File lib/funcify/monad.rb, line 35
def maybe_value
  ->(v) { v.value_or }
end
maybe_value_fail?() click to toggle source
# File lib/funcify/monad.rb, line 31
def maybe_value_fail?
  -> m { m.respond_to?(:failure?) && m.failure? }
end
maybe_value_ok?() click to toggle source
# File lib/funcify/monad.rb, line 27
def maybe_value_ok?
  -> m { m.respond_to?(:success?) && m.success? }
end
success() click to toggle source

> success.(:ok) => Success(:ok)

# File lib/funcify/monad.rb, line 23
def success
  -> value { Success(value) }
end
try_maybe_failure() click to toggle source
# File lib/funcify/monad.rb, line 43
def try_maybe_failure
  -> v {
    v.respond_to?(:failure) ? v.failure : v.exception
  }
end