Class: Funcify::Monad

Inherits:
Object
  • Object
show all
Extended by:
Dry::Monads::Result::Mixin
Defined in:
lib/funcify/monad.rb

Class Method Summary collapse

Class Method Details

.failureObject

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



18
19
20
# File 'lib/funcify/monad.rb', line 18

def failure
  -> value { Failure(value) }
end

.liftObject

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_failureObject



39
40
41
# File 'lib/funcify/monad.rb', line 39

def maybe_failure
  -> v { v.failure }
end

.maybe_valueObject



35
36
37
# File 'lib/funcify/monad.rb', line 35

def maybe_value
  ->(v) { v.value_or }
end

.maybe_value_fail?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/funcify/monad.rb', line 27

def maybe_value_ok?
  -> m { m.respond_to?(:success?) && m.success? }
end

.successObject

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



23
24
25
# File 'lib/funcify/monad.rb', line 23

def success
  -> value { Success(value) }
end

.try_maybe_failureObject



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