Iron v1.1.2
Introduction
This release adds multiple improvements to Iron without breaking changes.
Features
New alias for Constrained[A, B]
The old alias A ==> B
is replaced by A / B
to fit the set notation in maths: S / P(x)
Algebra system
A new algebra system that allows user to chain operators of the same algebra type and to write their constraints in a more mathematical way.
From #35 :
- Add placeholder type
??
. Other candidates?
,_
and???
are already taken. - Constraints can now belong to a specific algebra
- Algebra entry points can be used with the
??
placeholder:Double / (-1d < ?? < 1d)
desugars toDouble / (Greater[-1d] && Less[1d])
. It is also possible to use different constraints as long as they belong to the same algebra. - Algebra elements of the same type can be chained.
-1d < ?? < 1d < 2d < ...
.
Note: chaining is disallowed in before the placeholder??
to keep allowingDouble < 1d
and similar syntax. For example,-1 < ??
is allowed but-2d < -1d < ??
isn't.
Composed constraints now support compile-time evaluation
And
, Not
, Or
and similar constraints can now be evaluated at compile-time. Example:
def foo(x: Double / (Divisible[2d] && Greater[0d])): Unit = ???
foo(1d) //compile-time error
foo(-2d) //compile-time error
foo(2d) //This is fine
Iron Numeric
Iron numeric was updated to take advantage of the mentioned features. Version of this update: 1.1-1.0.1
Test it
Here is an interactive example using the described changes.
Code
import io.github.iltotore.iron.*, constraint.{*, given}, numeric.constraint.{*, given}
def acos(x: Double / ((-1d <= ?? <= 1d) DescribedAs "x should be a cosinus")): Refined[Double] = x.map(Math.acos)
println(acos(1d))