Validator

zio.prelude.Validator
abstract class Validator[A](f: A => Either[AssertionError, Unit])(implicit evidence$1: FromExpr[A]) extends Liftables

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
trait Liftables
class Object
trait Matchable
class Any

Members list

Type members

Inherited classlikes

object LiteralLift

Attributes

Inherited from:
Liftables
Supertypes
class Object
trait Matchable
class Any
object LiteralUnlift

Attributes

Inherited from:
Liftables
Supertypes
class Object
trait Matchable
class Any

Attributes

Inherited from:
Liftables
Supertypes
trait FromExpr[Regex]
class Object
trait Matchable
class Any
object given_ToExpr_Regex extends ToExpr[Regex]

Attributes

Inherited from:
Liftables
Supertypes
trait ToExpr[Regex]
class Object
trait Matchable
class Any

Value members

Concrete methods

final def validateInlineImpl(expr: Expr[A])(using Quotes): Expr[Unit]

Givens

Inherited givens

Attributes

Inherited from:
Liftables

Attributes

Inherited from:
Liftables

Attributes

Inherited from:
Liftables