Iron v1.2.0
Introduction
This release polishes v1.1.2 and adds a new alternative DSL.
Features
Imperative DSL
A capability to use refined types in an imperative-style. Based on HOPE 2021 Martin Odersky's talk:
//Monadic version
def log(x: Double > 0d): Refined[Double] = x.map(Math.log)
//Imperative version
def log(x: Double > 0d): Raw[Double] = refined {
Math.log(x)
}
Note: Raw[Double]
is a value contrained by an always-valid constraint. It is different from Refined[Double]
which is an alias for Either[IllegalValueError, Double]
more interoperability between Constrained
and monads will be added in 2.0.0 due to possible breaking changes.
Consequences
A constrained-to-constrained version of constraints (which are value-to-constrained). It allows refinements of already-constrained variables and use relations to avoid unnecessary evaluation:
val x: Double < 5d = 3d
val y: Double < 10d = x //5d < 10d will be verified at compile-time
val a: Double / Less[5d] = 3d
val b: Double / Not[Less[5d]] = a //Fails at compile time
See the wiki for further information.
Note: this works with all kind of constraints. Not only numeric.
Due to a compiler limitation, some "complex" consequences cannot be created yet.
Planned for 2.0.0
The next major release (2.0.0) will contain the following features:
- Polishing of the current API (simplification and standardisation of the current API, hiding internal components etc...)
- More interoperability between Constrained and other monads
- Better compile-time evaluation (keep in mind the inner value of a
Constrained
at compile-time if exists, more out of the box Consequences etc...)
Happy new year 🎉