So there have been a few times where it would be nice to simply nullify a value if a type is invalid. Imagine we have this type:
EmailAddress ||= begin Types::String .constructor(&:downcase) .constructor(&:strip) .constrained(format: URI::MailTo::EMAIL_REGEXP) end
Currently, you can use
.lax to rescue and return the input:
EmailAddress.lax.call('bad') #=> bad
This is useful, but it would be much more useful to be able to nil out the value. This would make it much easier to filter our junky data that’s is not business critical.
EmailAddress.lax(nil: true).call('bad') #=> nil`
Would y’all be open to adding this?