Sha256: 079ee9e1c830b54041ea43719cd3078b7f241656c7c6c839946d968f1a933595
Contents?: true
Size: 598 Bytes
Versions: 3
Compression:
Stored size: 598 Bytes
Contents
--- title: Sum layout: gem-single name: dry-types order: 7 --- You can specify sum types using `|` operator, it is an explicit way of defining what the valid types of a value are. For example `dry-types` defines the `Bool` type which is a sum consisting of the `True` and `False` types, expressed as `Types::True | Types::False`. Another common case is defining that something can be either `nil` or something else: ``` ruby nil_or_string = Types::Nil | Types::String nil_or_string[nil] # => nil nil_or_string["hello"] # => "hello" nil_or_string[123] # raises Dry::Types::ConstraintError ```
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dry-types-1.2.2 | docsite/source/sum.html.md |
dry-types-1.2.1 | docsite/source/sum.html.md |
dry-types-1.2.0 | docsite/source/sum.html.md |