Releases: fthomas/refined
0.2.2
Changes
- Introduce the
RefType
type class which abstracts overshapeless.tag.@@
andRefined
and that allows 3rd-party types to be used as result type
for refinements (e.g.scalaz.@@
).RefType
replaces the
now removedinternal.Wrapper
type class. (#48, #53, #54) - Make the
Refined
constructor private (#52)
Released on 2015-08-17
0.2.1
Changes
- Improve error messages of predicates created from partial functions.
(This includesRegex
,Url
,Xml
, and more.) - Add
unwrap
function to theinternal.Wrapper
type class.
New predicates
Xml
: checks if aString
is valid XMLXPath
: checks if aString
is a valid XPath expression
Released on 2015-08-06
0.2.0
Changes
- Deprecate
refine
andrefineLit
in favor of the newrefineT
and
refineMT
(whereT
stands for tag/@@
andM
for macro). In addition,
there are two other variants of these functions,refineV
andrefineMV
,
that use the newly addedRefined
value class instead of@@
. The advantages
ofRefined
is that it can be used in combination with
type aliases. - Add string utility functions to create statically checked regular expressions,
URIs, URLs, and UUIDs. A detailed description of these functions can be found
here. (#35, #38) - Lift the restriction to refine only literal values at compile-time if a
Predicate
is constant (i.e. it ignores its argument when callingisValid
).
Some examples of constant predicates areTrue
orFalse
or the newly added
ConstructorNames
andFieldNames
predicates. Some examples of the last two
predicates can be found here. (#26) - Enable tests in the Scala.js build. (#29)
- Remove
refine
fromPredicate
since the purpose ofPredicate
is
to check whether a value conforms to a type-level predicate. Refining
the type of such value is a different concern. (#31) - Add inference rules for numeric singleton types to
shapeless.Nat
.
New predicates
ConstructorNames[P]
: checks if the constructor names of a sum type satisfyP
FieldNames[P]
: checks if the field names of a product type satisfyP
Uuid
: checks if aString
is a valid UUID
Released on 2015-07-27
0.1.3
0.1.2
Changes
- Add
refine
function to thePredicate
type class. - Add
Predicate.fromPartial
for creating aPredicate
from a partial function. - Update to Scala 2.11.7 and Scala.js 0.6.4.
New predicates
Uri
: checks if aString
is a valid URIUrl
: checks if aString
is a valid URL
Released on 2015-07-06
0.1.1
0.1.0
Changes
-
Added inference rules to enable automatic conversions between different
refined types (in the absent of any subtype relation). For example, a value
of typeInt @@ Greater[_5]
can be safely converted to anInt @@ Positive
,
but the reverse is not true:scala> refineLit[Greater[_5]](10) res1: Int @@ Greater[_5] = 10 scala> res1: Int @@ Positive res2: Int @@ Positive = 10 scala> res2: Int @@ Greater[_5] <console>:42: error: invalid inference: Positive ==> Greater[_5] res2: Int @@ Greater[_5] ^
Note that these conversions need to be enabled with an import:
import eu.timepit.refined.implicits._
-
Added an implicit version of
refineLit
to theimplicits
object.
This allows to writeval a: Char @@ Digit = '4'
instead of
val a: Char @@ Digit = refineLit('4')
-
Made
Predicate
serializable. -
Removed
IsNull
andNonNull
predicates since they often caused ambiguous
implicit errors and Scala has better means to handlenull
values.
Bug fixes
refineLit
always required a prior import ofshapeless.tag.@@
. (9f6d7d9)- Changed build to multi-project build so that tut-core is not added as
dependency to refined. (#17)
New predicates
NonPositive
: checks if a numeric value is zero or negativeNonNegative
: checks if a numeric value is zero or positive
EndsWith[S]
: checks if aString
ends with the suffixS
Regex
: checks if aString
is a valid regular expressionStartsWith[S]
: checks if aString
starts with the prefixS
Released on 2015-06-20
0.0.3
Changes
- Added
Predicate
instances for numeric predicates that take singleton
types as arguments. For examplerefineLit[Less[W.
-12.3.T]](-12.5)
checks at compile time that -12.5 is less than -12.3. refine
andrefineLit
are now regular functions and notobject
s
with anapply
method.- Updated to shapeless 2.2.0.
Bug fixes
refineLit
works now with predicates that contain singleton types.
For examplerefineLit[MatchesRegex[W.
"[0-9]+".T](<string literal>)
checks at compile-time if<string literal>
matches the regular
expression "[0-9]+". (#2)- Worked around a strange initialization bug in
refineLit
. (#3)
New predicates
Xor[A, B]
: exclusive disjunction of the predicatesA
andB
OneOf[PS]
: exclusive disjunction of all predicates inPS
LetterOrDigit
: checks if aChar
is a letter or digit
Contains[U]
: checks if aTraversableOnce
contains a value equal toU
Head[P]
: checks if the predicateP
holds for the first element of
aTraversable
Index[N, P]
: checks if the predicateP
holds for the element at
indexN
of a sequenceLast[P]
: checks if the predicateP
holds for the last element of
aTraversable
IsNull
: checks if a value isnull
NonNull
: checks if a value is notnull
Released on 2015-05-31
0.0.2
Changes
- Nicer syntax for
refine
andrefineLit
. The type that is refined does not
need to be specified anymore. E.g. there is no need to specifyChar
in
refineLit[AnyOf[Digit :: Letter :: Whitespace :: HNil]]('F')
.
New predicates
AllOf[PS]
: conjunction of all predicates inPS
AnyOf[PS]
: disjunction of all predicates inPS
Digit
: checks if aChar
is a digitLetter
: checks if aChar
is a letterWhitespace
: checks if aChar
is white space
Count[PA, PC]
: counts the number of elements in aTraversableOnce
which satisfy the predicatePA
and passes the result to the numeric
predicatePC
MinSize[N]
: checks if the size of aTraversableOnce
is greater than
or equal toN
MaxSize[N]
: checks if the size of aTraversableOnce
is less than
or equal toN
Equal[U]
: checks if a value is equal toU
MatchesRegex[R]
: checks if aString
matches the regular expressionR
Released on 2015-05-22
0.0.1
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