View Source Elixact.Types (elixact v0.1.2)
Core type system for Elixact schemas.
Provides functions for defining and working with types:
- Basic types (:string, :integer, :float, :boolean)
- Complex types (arrays, maps, unions)
- Type constraints
- Type validation
- Type coercion
Basic Types
# String type
Types.string()
# Integer type with constraints
Types.integer()
|> Types.with_constraints(gt: 0, lt: 100)
Complex Types
# Array of strings
Types.array(Types.string())
# Map with string keys and integer values
Types.map(Types.string(), Types.integer())
# Union of types
Types.union([Types.string(), Types.integer()])
Type Constraints
Constraints can be added to types to enforce additional rules:
Types.string()
|> Types.with_constraints([
min_length: 3,
max_length: 10,
format: ~r/^[a-z]+$/
])
Summary
Types
@type type_definition() :: {:type, atom(), [any()]} | {:array, type_definition(), [any()]} | {:map, {type_definition(), type_definition()}, [any()]} | {:union, [type_definition()], [any()]} | {:ref, atom()}