Class: Fried::Typings::HashOf

Inherits:
Object
  • Object
show all
Includes:
MetaType, Type
Defined in:
lib/fried/typings/hash_of.rb

Overview

Checks if all key => value elements of the hashmap match the types pair

Instance Method Summary collapse

Methods included from Type

#<=>, #call, included

Methods included from MetaType

included

Constructor Details

#initialize(key_type, value_type) ⇒ HashOf

Returns a new instance of HashOf.



21
22
23
24
# File 'lib/fried/typings/hash_of.rb', line 21

def initialize(key_type, value_type)
  @key_type = key_type
  @value_type = value_type
end

Instance Method Details

#valid?(hsh) ⇒ Boolean

Parameters:

  • hsh (Hash)

Returns:



27
28
29
30
31
32
33
# File 'lib/fried/typings/hash_of.rb', line 27

def valid?(hsh)
  return false unless Is[Hash].valid?(hsh)

  enumerator = hsh.each

  EnumeratorOf[TupleOf[key_type, value_type]].valid?(enumerator)
end