Packages

object syntax extends RuleHListSyntax

Provides rule-builder style methods for refining types during the validation process.

This can be useful for situations where your input types may be raw user input data which you validate, and then from that validation you gain additional context.

Consider The example below:

case class InputFoo(untrimmed: String, maybeEmptyList: List[Int], name: String)
case class ValidatedFoo(trimmed: String, nonEmptyList: NonEmptyList[Int], name: String, thing: Double)

val rule =
  Rule.builder[InputFoo]
    .check("untrimmed", _.untrimmed)(Rule.trimString)
    .check("maybeEmptyList", _.maybeEmptyList)(Rule.nonEmptyList)
    .pass(_.name) // No validation will be performed, but the value for name will be passed through.
    .append(util.Random.nextDouble()) // Appends a random double to the output type
    .build[ValidatedFoo]

rule(InputFoo("bar ", List("baz"))) // Ior.Right(ValidatedFoo("bar", NonEmptyList("baz")))
rule(InputFoo("bar", List()) // Ior.Left(NonEmptyList(ErrorMessage("Must not be empty", PField("maybeEmptyList", PNil))))

A user has input an untrimmed string, and a list that may be empty. During the sanitization and validation process, the string is trimmed, and then the List[Int] becomes a NonEmptyList[Int]. This is because the sanitization process can refine the type and hold on to context from the validation phase. This could also be used in conjunction with things like string parsing engines to accept user input strings, parse them in to your AST during sanitization/validation.

Linear Supertypes
RuleHListSyntax, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. syntax
  2. RuleHListSyntax
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. implicit class RuleHList [A, B <: HList, Rev <: HList] extends AnyRef
    Definition Classes
    RuleHListSyntax
  2. implicit class RuleObjectOps extends AnyRef
    Definition Classes
    RuleHListSyntax

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  16. def toString(): String
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from RuleHListSyntax

Inherited from AnyRef

Inherited from Any

Ungrouped