Packages

p

purity

package purity

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. case class ConsistentParse[E, A, B](p: Proposition[E, B], parsing: (A) ⇒ ValidatedNel[E, B]) extends Product with Serializable
  2. trait Predicate[-A] extends AnyRef
  3. 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.

  4. 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

  1. object ConsistentParse extends ConsistentFunctions with ConsistentInstances with Serializable
  2. object Predicate extends PredicateFunctions with PredicateInstances
  3. object Proposition extends PropositionFunctions with PropositionInstances
  4. object Truth extends TruthFunctions with TruthInstances

Ungrouped