← ZIO Prelude docs

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

Source
Validator.scala
Graph
Supertypes
trait Liftables
class Object
trait Matchable
class Any

Members list

Type members

Inherited classlikes

object LiteralLift

Attributes

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

Attributes

Inherited from:
Liftables
Source
Liftables.scala
Supertypes
class Object
trait Matchable
class Any
object given_FromExpr_Regex extends FromExpr[Regex]

Attributes

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

Attributes

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

Value members

Concrete methods

def validate(a: A): Either[AssertionError, Unit]

Attributes

Source
Validator.scala
final def validateInlineImpl(expr: Expr[A])(using Quotes): Expr[Unit]

Attributes

Source
Validator.scala

Givens

Inherited givens

given given_FromExpr_Assertion[A](using x$1: Type[A]): given_FromExpr_Assertion[A]

Attributes

Inherited from:
Liftables
Source
Liftables.scala

Attributes

Inherited from:
Liftables
Source
Liftables.scala

Attributes

Inherited from:
Liftables
Source
Liftables.scala