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
Ordering
- Alphabetic
- By Inheritance
Inherited
- syntax
- RuleHListSyntax
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Type Members
-
implicit
class
RuleHList
[A, B <: HList, Rev <: HList] extends AnyRef
- Definition Classes
- RuleHListSyntax
-
implicit
class
RuleObjectOps
extends AnyRef
- Definition Classes
- RuleHListSyntax
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )