purity
package purity
- Alphabetic
- Public
- All
Type Members
- case class ConsistentParse[E, A, B](p: Proposition[E, B], parsing: (A) ⇒ ValidatedNel[E, B]) extends Product with Serializable
- trait Predicate[-A] extends AnyRef
-
trait
Proposition[+E, -A] extends AnyRef
A data type for lazy consistency checks on a data structure.
A data type for lazy consistency checks on a data structure.
A Proposition wraps a function that checks a proposition of a logical statement over a type. Combinators like leftMap, contramap, &&, ||, and not, can be used to easily create more complex checks.
val a = Proposition[String, Int](x => if(x > 10) False("age should be less than 10") else True) //a: purity.Proposition[String,Int] = Proposition a.check(21) //res0: purity.Truth[String] = False(NonEmptyList(age should be less than 10)) a.check(9) //res1: purity.Truth[String] = True val b = Proposition[String, String](x => if(x.length > 2) False("name code should be less than 3") else True) //b: purity.Proposition[String,String] = Proposition val c = a.contramap[User](_.age) && b.contramap[User](_.name) //c: purity.Proposition[String,User] = Proposition c.check(User("FAF", 21)) //res3: purity.Truth[String] = False(NonEmptyList(age should be less than 10, name code should be less than 3))
- E
type of the failure in case of an False result.
- A
type to be checked for consistency.
-
sealed
trait
Truth[+E] extends AnyRef
Coproduct that represents a logical truth.
Coproduct that represents a logical truth. Truth is either True or False(e)
One may also view the Truth data type as an inverse Option, or a cats Validated with the Valid type parameter set to Unit.
Contains combinators map, not, &&, ||
- E
type which encodes possible failures (The False data type will contain a non empty list of these)
Value Members
- object ConsistentParse extends ConsistentFunctions with ConsistentInstances with Serializable
- object Predicate extends PredicateFunctions with PredicateInstances
- object Proposition extends PropositionFunctions with PropositionInstances
- object Truth extends TruthFunctions with TruthInstances