github fthomas/refined 0.0.1

latest releases: v0.11.2, v0.11.1, v0.11.0...
8 years ago

First public release of refined.

Overview

This is a port of the refined Haskell library to Scala.
The linked websites provides an excellent motivation why this kind of library
is useful.

This library consists of:

  • Type-level predicates for refining other types, like UpperCase, Positive,
    Greater[_0] And LessEqual[_2], or Length[Greater[_5]]. There are also higher
    order predicates for combining proper predicates like And[_, _], Or[_, _],
    Not[_], Forall[_], or Size[_].
  • A Predicate type class that is able to validate a concrete data type (like Double)
    against a type-level predicate (like Positive).
  • Two functions refine and refineLit that take a predicate P and some value
    of type T, validates this value with a Predicate[P, T] and returns the value
    with type T @@ P if validation was successful or an error otherwise.
    (@@ is shapeless' type for tagging types :-))

Provided predicates

The library comes with these predefined predicates:

boolean

  • True: constant predicate that is always true
  • False: constant predicate that is always false
  • Not[P]: negation of the predicate P
  • And[A, B]: conjunction of the predicates A and B
  • Or[A, B]: disjunction of the predicates A and B

char

  • LowerCase: checks if a Char is a lower case character
  • UpperCase: checks if a Char is an upper case character

collection

  • Empty: checks if a TraversableOnce is empty
  • NonEmpty: checks if a TraversableOnce is not empty
  • Forall[P]: checks if the predicate P holds for all elements of a
    TraversableOnce
  • Exists[P]: checks if the predicate P holds for some elements of a
    TraversableOnce
  • Size[P]: checks if the size of a TraversableOnce satisfies the predicate P

numeric

  • Less[N]: checks if a numeric value is less than N
  • LessEqual[N]: checks if a numeric value is less than or equal to N
  • Greater[N]: checks if a numeric value is greater than N
  • GreaterEqual[N]: checks if a numeric value is greater than or equal to N
  • Equal[N]: checks if an integral value is equal to N
  • Positive: checks if a numeric value is greater than zero
  • Negative: checks if a numeric value is less than zero
  • ZeroToOne: checks if a numeric value is in the interval [0, 1]

Released on 2015-05-15

Don't miss a new refined release

NewReleases is sending notifications on new releases.