Class: Kleisli::Contracts::EitherOf
Instance Method Summary
collapse
Methods inherited from KContract
#initialize
Instance Method Details
#monad_valid(val) ⇒ Object
30
31
32
33
|
# File 'lib/kleisli/contracts.rb', line 30
def monad_valid(val)
[Kleisli::Either::Left, Kleisli::Either::Right].
include?(val.class)
end
|
#valid?(val) ⇒ Boolean
34
35
36
37
38
39
40
41
|
# File 'lib/kleisli/contracts.rb', line 34
def valid?(val)
return false unless monad_valid(val) &&
@inner_types.size == 2
left_valid, _ = Contract.valid?(val.left, @inner_types.first)
right_valid, _ = Contract.valid?(val.right, @inner_types.last)
(val.left.nil? && right_valid) ||
(val.right.nil? && left_valid)
end
|