Bond - Type-level validation for Scala

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bond - Type-level validation for Scala

Flávio Brasil-2

I’ve just pushed to maven central the first release of Bond. It is a library to express validation constraints using the type system. Some usage examples:

import net.fwbrasil.bond._

case class Employee (
    name: String with NonEmpty,
    email: String with Email,
    age: Int with GreaterThan[T.`14`.T]
)

case class Company (
    employees: List[Employee] with MinSize[T.`2`.T]
)

val employeeAge: Int with GreaterThan[T.`14`.T] = ...

val lifted: Int with GreaterThan[T.`12`.T] =
    GreaterThan(12).lift(employee.age)

GreaterThan(18).lift(employee.age)

[error] The lifting of 'Int with net.fwbrasil.bond.GreaterThan[Int(14)]'' to 'net.fwbrasil.bond.GreaterThan[Int(18)]' is not valid (Bond)
[error]         GreaterThan(18).lift(employee.age)
[error]                             ^


Regards,

-- 
Flavio W. Brasil
http://fwbrasil.net

--
You received this message because you are subscribed to the Google Groups "scala-announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.