Class: Kleisli::Contracts::MaybeOf

Inherits:
KContract
  • Object
show all
Defined in:
lib/kleisli/contracts.rb

Instance Method Summary collapse

Methods inherited from KContract

#initialize

Constructor Details

This class inherits a constructor from Kleisli::Contracts::KContract

Instance Method Details

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/kleisli/contracts.rb', line 21

def valid?(val)
  return false unless val.kind_of?(Kleisli::Maybe) &&
    @inner_types.size == 1
  inner_valid, _ = Contract.valid?(val.value, @inner_types.first)
  inner_valid || val.value.nil?
end