Rule

erules.core.Rule
See theRule companion object
sealed trait Rule[+F[_], -T] extends Serializable

Attributes

Companion:
object
Graph
Supertypes
trait Serializable
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

def contramap[U](cf: U => T): Rule[F, U]

Contravariant version of the map.

Contravariant version of the map.

Given a large class with nested case class for example. In order to test a single rule without stud all useless data you may want to create a rule for the specific type and not for the whole class.


 class Region(value: String) extends AnyVal
 class Citizenship(region: Region)
 class User(name: String, age: Int, citizenship: Citizenship)

 val checkRegionIsUK: Rule[Region] = Rule("Check region is UK").check {
     case Region("UK") => Allow.withoutReasons
     case Region(value) => Deny.because(s"Only UK region is accepted! Actual value: $$value")
 }

In this case if you want to apply this rule to a User instance con can use the contramap method.

 val checkUser: Rule[User] = checkRegionIsUK.contramap(_.citizenship.region)

NOTE: using generic module, with import erules.generic.implicits.* you can use contramapTarget to both contramap and add target information.

Attributes

def covary[G[_] : Applicative](implicit evidence$1: Applicative[G], env: F[RuleVerdict] <:< RuleVerdict): Rule[G, T]

Lift a pure, side-effect free rule with effect Id[_] to specified G[_]. Value is lifted as a pure effect using Applicative

Lift a pure, side-effect free rule with effect Id[_] to specified G[_]. Value is lifted as a pure effect using Applicative

Attributes

G

Effect

Returns:

A lifted rule to specifed effect type G

def describe(description: String): Rule[F, T]

Set rule description

Set rule description

Attributes

def evalRaw[FF[X], TT <: T](data: TT): FF[RuleVerdict]

Same as eval but has only the RuleVerdict value

Same as eval but has only the RuleVerdict value

Attributes

def targetInfo(targetInfo: String): Rule[F, T]

In this case if you want to apply this rule to a User instance con can use the contramap method.

  • Given a large class with nested case class for example. In order to test a single rule without stud all useless data you may want to create a rule for the specific type and not for the whole class.

 class Region(value: String) extends AnyVal
 class Citizenship(region: Region)
 class User(name: String, age: Int, citizenship: Citizenship)

 val checkRegionIsUK: Rule[Region] = Rule("Check region is UK").check {
     case Region("UK") => Allow.withoutReasons
     case Region(value) => Deny.because(s"Only UK region is accepted! Actual value: $$value")
 }

In this case if you want to apply this rule to a User instance con can use the contramap method.

 val checkUser: Rule[User] = checkRegionIsUK.contramap(_.citizenship.region)

But dosing this if you want to keep the information that this rule doesn't check the whole User instance but just a small sub-set of the data you can use targetInfo method to add this information to this rule.

The typical value of this method is "string" version of the contramap parameter.

 val checkUser: Rule[User] = checkRegionIsUK
 .contramap(_.citizenship.region)
 .targetInfo("citizenship.region")

NOTE: using generic module, with import erules.generic.implicits.* you can use contramapTarget to both contramap and add target information.

Attributes

Concrete methods

final override def equals(obj: Any): Boolean

Compares the receiver object (this) with the argument object (that) for equivalence.

Compares the receiver object (this) with the argument object (that) for equivalence.

Any implementation of this method should be an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode to ensure that objects which are "equal" (o1.equals(o2) returns true) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)).

Attributes

that

the object to compare against this object for equality.

Returns:

true if the receiver object is equivalent to the argument; false otherwise.

Definition Classes
Any
final def eval[FF[X], TT <: T](data: TT)(implicit F: ApplicativeThrow[FF], C: Clock[FF]): FF[Free[TT]]

Eval this rules. The evaluations result is stored into a 'Either[Throwable, T]', so the ApplicativeError doesn't raise error in case of failed rule evaluation

Eval this rules. The evaluations result is stored into a 'Either[Throwable, T]', so the ApplicativeError doesn't raise error in case of failed rule evaluation

Attributes

def fullDescription: String

A full description of the rule, that contains name, description and target info where defined.

A full description of the rule, that contains name, description and target info where defined.

Attributes

Abstract fields

val description: Option[String]

A string to add more information to this rule.

A string to add more information to this rule.

Attributes

val name: String

A string to describe in summary this rule.

A string to describe in summary this rule.

Attributes

val targetInfo: Option[String]

A string to describe what/who is the target of this rule.

A string to describe what/who is the target of this rule.

Attributes