hash_validator icon indicating copy to clipboard operation
hash_validator copied to clipboard

Feature Request: Union

Open ellcs opened this issue 4 years ago • 0 comments

Hello james! I have a feature request. Most modern languages have a concept named union types:

  • https://crystal-lang.org/reference/syntax_and_semantics/union_types.html
  • https://sorbet.org/docs/union-types
  • https://www.schoolofhaskell.com/user/Gabriel439/sum-types

The type is an element of a set. I know it's easy to write with as a lambda. But it's way better to read, when you have a notation like HashValidator::Union[*typesl]. Another name could be HashValidator::Or.

class Email; attr_accessor :text; end

# Validations hash
validators = {  email: HashValidator::Union[String, Email] }

# First case, it's a String
user1 =  { email: '[email protected]' }
HashValidator.validate(user1, validations)

# Second case, it's an Email
email = Email.new
email.text = '[email protected]'
user2 =  { email: email }
HashValidator.validate(user2, validations)

ellcs avatar May 18 '20 17:05 ellcs