Dear Russian friends, please watch President Zelenskyy's speech addressed to you. πŸ‡ΊπŸ‡¦Help our brave mates in Ukraine with a donation.

Type Attributes

Types themselves have optional attributes you can apply to get further functionality.

Append .optional to a Type to allow nil

By default, nil values raise an error:

# => raises Dry::Types::ConstraintError

Add .optional and nil values become valid:

optional_string = Types::Strict::String.optional

# => nil
# => "something"
# raises Dry::Types::ConstraintError

Types::String.optional is just syntactic sugar for Types::Strict::Nil | Types::Strict::String.

Handle optional values using Monads

See Maybe extension for another approach to handling optional values by returning a Monad object.

octocatEdit on GitHub