dry-types

v1.8 v1.7
  1. Introduction
  2. Getting Started
  3. Built-in Types
  4. Type Attributes
  5. Default Values
  6. Fallbacks
  7. Sum
  8. Constraints
  9. Hash Schemas
  10. Array With Member
  11. Enum
  12. Map
  13. Custom Types
  14. Custom Type Builders
  15. Extensions
    1. Maybe
    2. Monads

TOC


Map

Map describes a homogeneous hashmap. This means only types of keys and values are known. You can simply imagine a map input as a list of key-value pairs.

int_float_hash = Types::Hash.map(Types::Integer, Types::Float)
int_float_hash[100 => 300.0, 42 => 70.0]
# => {100=>300.0, 42=>70.0}

# Only accepts mappings of integers to floats
int_float_hash[name: 'Jane']
# => Dry::Types::MapError: input key :name is invalid: type?(Integer, :name)