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]
, orLength[Greater[_5]]
. There are also higher
order predicates for combining proper predicates likeAnd[_, _]
,Or[_, _]
,
Not[_]
,Forall[_]
, orSize[_]
. - A
Predicate
type class that is able to validate a concrete data type (likeDouble
)
against a type-level predicate (likePositive
). - Two functions
refine
andrefineLit
that take a predicateP
and some value
of typeT
, validates this value with aPredicate[P, T]
and returns the value
with typeT @@ P
if validation was successful or an error otherwise.
(@@
is shapeless' type for tagging types :-))
Provided predicates
The library comes with these predefined predicates:
True
: constant predicate that is alwaystrue
False
: constant predicate that is alwaysfalse
Not[P]
: negation of the predicateP
And[A, B]
: conjunction of the predicatesA
andB
Or[A, B]
: disjunction of the predicatesA
andB
LowerCase
: checks if aChar
is a lower case characterUpperCase
: checks if aChar
is an upper case character
Empty
: checks if aTraversableOnce
is emptyNonEmpty
: checks if aTraversableOnce
is not emptyForall[P]
: checks if the predicateP
holds for all elements of a
TraversableOnce
Exists[P]
: checks if the predicateP
holds for some elements of a
TraversableOnce
Size[P]
: checks if the size of aTraversableOnce
satisfies the predicateP
Less[N]
: checks if a numeric value is less thanN
LessEqual[N]
: checks if a numeric value is less than or equal toN
Greater[N]
: checks if a numeric value is greater thanN
GreaterEqual[N]
: checks if a numeric value is greater than or equal toN
Equal[N]
: checks if an integral value is equal toN
Positive
: checks if a numeric value is greater than zeroNegative
: checks if a numeric value is less than zeroZeroToOne
: checks if a numeric value is in the interval [0, 1]
Released on 2015-05-15