Validator
zio.prelude.Validator
Convience type that helps with defining a Newtype with a custom (so anything that is not expressable with an Assertion) predicate that should be checked during compile-time.
Define this in a separate file then the Newtype itself!
File 1:
import zio.prelude.Validator
object PalindromeValidator extends Validator[String](str =>
if (str.reverse == str) Right(()) else Left(AssertionError.failure("isPalindrome"))
)
File 2:
type Palindrome = Palindrome.type
object Palindrome extends NewtypeCustom[String] {
protected def validate(value: Int) = PalindromeValidator.validate(value)
protected inline def validateInline(inline value: Int) =
${ PalindromeValidator.validateInlineImpl('value) }
}
Attributes
- Graph
-
- Supertypes
Members list
In this article