You can specify sum types using
| operator, it is an explicit way of defining what the valid types of a value are.
dry-types defines the
Bool type which is a sum consisting of the
False types, expressed as
Types::True | Types::False (and it has its strict version, too).
Another common case is defining that something can be either
nil or something else:
nil_or_string = Types::Strict::Nil | Types::Strict::String nil_or_string[nil] # => nil nil_or_string["hello"] # => "hello" nil_or_string # raises Dry::Types::ConstraintError