Packages

object Assertion

An Assertion[A] is essentially a composable predicate from A => Boolean. They can be composed with standard Boolean operators of &&, || and !. This is primarily intended to be used with Newtype and Subtype, enhancing them with compile-time time validation.

For example, if you'd like to validate that a particular Int is precisely 4 digits long, you can create the following refined Newtype. (Note that the syntax is slightly difference between Scala 2 and Scala 3).

type Pin = Pin.Type
object Pin extends Newtype[Int] {
  // Scala 2 Syntax
  def assertion =
    assert(Assertion.between(1000, 9999))

  // Scala 3 Syntax
  override inline def assertion =
    Assertion.between(1000, 9999)
}

// PowerOfTwo(1000) compiles
// PowerOfTwo(5412) compiles
// PowerOfTwo(34567) fails with "34567 did not satisfy between(1000, 9999)"
// PowerOfTwo(234) fails with "123 did not satisfy between(1000, 9999)"
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Assertion
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. sealed trait Regex extends AnyRef

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. val anything: Assertion[Any]
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def between[A](min: A, max: A)(implicit ordering: Ordering[A]): Assertion[A]

    Ensures the value falls between a given min and max (inclusive).

  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  8. def contains(string: String): Assertion[String]
  9. def divisibleBy[A](n: A)(implicit numeric: Numeric[A]): Assertion[A]
  10. def endsWith(suffix: String): Assertion[String]
  11. def endsWithIgnoreCase(suffix: String): Assertion[String]
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equalTo[A](value: A): Assertion[A]
  14. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  16. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  17. def greaterThan[A](value: A)(implicit ordering: Ordering[A]): Assertion[A]
  18. def greaterThanOrEqualTo[A](value: A)(implicit ordering: Ordering[A]): Assertion[A]
  19. def hasLength(lengthAssertion: Assertion[Int]): Assertion[String]
  20. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  21. val isEmptyString: Assertion[String]
  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. def lessThan[A](value: A)(implicit ordering: Ordering[A]): Assertion[A]
  24. def lessThanOrEqualTo[A](value: A)(implicit ordering: Ordering[A]): Assertion[A]
  25. def matches(regex: scala.util.matching.Regex): Assertion[String]

    Matches a scala.util.matching.Regex.

    Matches a scala.util.matching.Regex.

    In order to use this for compile-time Assertions, make sure to use the string literal extension method, e.g.:

    Assertion.matches("\\w+@\\d{3,5}".r)
  26. def matches(regexString: String): Assertion[String]
  27. def matches(regex: Regex): Assertion[String]
  28. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  29. val never: Assertion[Any]
  30. def notEqualTo[A](value: A): Assertion[A]
  31. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  32. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  33. def powerOf[A](base: A)(implicit numeric: Numeric[A]): Assertion[A]

    Ensures that the value is a power of the given base.

    Ensures that the value is a power of the given base.

    type PowerOfTwo = PowerOfTwo.Type
    object PowerOfTwo extends Newtype[Int] {
      def assertion =
        assert(Assertion.powerOf(2))
    }
    
    // PowerOfTwo(1024) compiles
    // PowerOfTwo(1025) fails
  34. def startsWith(prefix: String): Assertion[String]
  35. def startsWithIgnoreCase(prefix: String): Assertion[String]
  36. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  37. def toString(): String
    Definition Classes
    AnyRef → Any
  38. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  39. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  40. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  41. object Regex

Inherited from AnyRef

Inherited from Any

Ungrouped