Skip to content

Releases: fthomas/refined

0.2.2

18 Nov 19:16
Compare
Choose a tag to compare

Changes

  • Introduce the RefType type class which abstracts over shapeless.tag.@@
    and Refined and that allows 3rd-party types to be used as result type
    for refinements (e.g. scalaz.@@). RefType replaces the
    now removed internal.Wrapper type class. (#48, #53, #54)
  • Make the Refined constructor private (#52)

Released on 2015-08-17

0.2.1

18 Nov 19:18
Compare
Choose a tag to compare

Changes

  • Improve error messages of predicates created from partial functions.
    (This includes Regex, Url, Xml, and more.)
  • Add unwrap function to the internal.Wrapper type class.

New predicates

string

  • Xml: checks if a String is valid XML
  • XPath: checks if a String is a valid XPath expression

Released on 2015-08-06

0.2.0

18 Nov 19:19
Compare
Choose a tag to compare

Changes

  • Deprecate refine and refineLit in favor of the new refineT and
    refineMT (where T stands for tag/@@ and M for macro). In addition,
    there are two other variants of these functions, refineV and refineMV,
    that use the newly added Refined value class instead of @@. The advantages
    of Refined 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 calling isValid).
    Some examples of constant predicates are True or False or the newly added
    ConstructorNames and FieldNames predicates. Some examples of the last two
    predicates can be found here. (#26)
  • Enable tests in the Scala.js build. (#29)
  • Remove refine from Predicate since the purpose of Predicate 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

generic

  • ConstructorNames[P]: checks if the constructor names of a sum type satisfy P
  • FieldNames[P]: checks if the field names of a product type satisfy P

string

  • Uuid: checks if a String is a valid UUID

Released on 2015-07-27

0.1.3

15 Jul 12:52
Compare
Choose a tag to compare

Changes

  • Update to shapeless 2.2.4.

New predicates

generic

  • Subtype[U]: witnesses that the type of a value is a subtype of U
  • Supertype[U]: witnesses that the type of a value is a supertype of U

0.1.2

18 Nov 19:23
Compare
Choose a tag to compare

Changes

  • Add refine function to the Predicate type class.
  • Add Predicate.fromPartial for creating a Predicate from a partial function.
  • Update to Scala 2.11.7 and Scala.js 0.6.4.

New predicates

string

  • Uri: checks if a String is a valid URI
  • Url: checks if a String is a valid URL

Released on 2015-07-06

0.1.1

18 Nov 19:24
Compare
Choose a tag to compare

Changes

  • Cross-build to Scala.js.
  • Updated to shapeless 2.2.3.

Released on 2015-06-27

0.1.0

18 Nov 19:29
Compare
Choose a tag to compare

Changes

  • Added inference rules to enable automatic conversions between different
    refined types (in the absent of any subtype relation). For example, a value
    of type Int @@ Greater[_5] can be safely converted to an Int @@ 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 the implicits object.
    This allows to write

    val a: Char @@ Digit = '4'

    instead of

    val a: Char @@ Digit = refineLit('4')
  • Made Predicate serializable.

  • Removed IsNull and NonNull predicates since they often caused ambiguous
    implicit errors and Scala has better means to handle null values.

  • Updated to shapeless 2.2.2. (#8, #13)

Bug fixes

  • refineLit always required a prior import of shapeless.tag.@@. (9f6d7d9)
  • Changed build to multi-project build so that tut-core is not added as
    dependency to refined. (#17)

New predicates

numeric

  • NonPositive: checks if a numeric value is zero or negative
  • NonNegative: checks if a numeric value is zero or positive

string

  • EndsWith[S]: checks if a String ends with the suffix S
  • Regex: checks if a String is a valid regular expression
  • StartsWith[S]: checks if a String starts with the prefix S

Released on 2015-06-20

0.0.3

18 Nov 19:30
Compare
Choose a tag to compare

Changes

  • Added Predicate instances for numeric predicates that take singleton
    types as arguments. For example refineLit[Less[W.-12.3.T]](-12.5)
    checks at compile time that -12.5 is less than -12.3.
  • refine and refineLit are now regular functions and not objects
    with an apply method.
  • Updated to shapeless 2.2.0.

Bug fixes

  • refineLit works now with predicates that contain singleton types.
    For example refineLit[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

boolean

  • Xor[A, B]: exclusive disjunction of the predicates A and B
  • OneOf[PS]: exclusive disjunction of all predicates in PS

char

  • LetterOrDigit: checks if a Char is a letter or digit

collection

  • Contains[U]: checks if a TraversableOnce contains a value equal to U
  • Head[P]: checks if the predicate P holds for the first element of
    a Traversable
  • Index[N, P]: checks if the predicate P holds for the element at
    index N of a sequence
  • Last[P]: checks if the predicate P holds for the last element of
    a Traversable

generic

  • IsNull: checks if a value is null
  • NonNull: checks if a value is not null

Released on 2015-05-31

0.0.2

18 Nov 19:31
Compare
Choose a tag to compare

Changes

  • Nicer syntax for refine and refineLit. The type that is refined does not
    need to be specified anymore. E.g. there is no need to specify Char in
    refineLit[AnyOf[Digit :: Letter :: Whitespace :: HNil]]('F').

New predicates

boolean

  • AllOf[PS]: conjunction of all predicates in PS
  • AnyOf[PS]: disjunction of all predicates in PS

char

  • Digit: checks if a Char is a digit
  • Letter: checks if a Char is a letter
  • Whitespace: checks if a Char is white space

collection

  • Count[PA, PC]: counts the number of elements in a TraversableOnce
    which satisfy the predicate PA and passes the result to the numeric
    predicate PC
  • MinSize[N]: checks if the size of a TraversableOnce is greater than
    or equal to N
  • MaxSize[N]: checks if the size of a TraversableOnce is less than
    or equal to N

generic

  • Equal[U]: checks if a value is equal to U

string

  • MatchesRegex[R]: checks if a String matches the regular expression R

Released on 2015-05-22

0.0.1

18 Nov 19:31
Compare
Choose a tag to compare

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