v2.2.0
Introduction
This release brings new constraints and a way to create zero-overhead new types from refined ones.
Main changes
New types
This release adds the RefinedTypeOps
trait. It adds smart constructors for refined types and can be combined with type aliases to emulate no-cost new types:
type Temperature = Int :| Positive
object Temperature extends RefinedTypeOps[Temperature]
val temperature: Temperature = Temperature(100)
val maybeTemperature: Option[Temperature] = Temperature.option(100)
val temperatureOrError: Either[String, Temperature] = Temperature.either(100)
It can also be combined with Scala 3's opaque types to avoid mixing similar new types:
opaque type Temperature = Int :| Positive
object Temperature extends RefinedTypeOps[Temperature]
opaque type Moisture = Int :| Positive
object Moisture extends RefinedTypeOps[Moisture]
case class WeatherData(temperature: Temperature, moisture: Moisture)
val temperature = Temperature(100)
val moisture = Moisture(10)
WeatherData(temperature, moisture) //OK
WeatherData(moisture, temperature) //Compile-time error: type mismatch
Note: due to a compiler issue, interaction between opaque new types and multi-module projects has some frictions. See #131
Check the dedicated documentation page for further information.
BigInt and BigDecimal support
The io.github.iltotore.iron.constraint.numeric
package now has support for scala.math.BigInt
and scala.math.BigDecimal
.
Supported constraints are:
- Greater
- Less
- Multiple
- Divide
- Associated aliases (e.g GreaterEqual, LessEqual, Positive, Even, ...)
Note: like List
, Set
etc..., these constraints are runtime only. It will be fixed in Iron 3.0, see #147.
Better documentation
The documentation is now versioned. You can select the version you want in the upper-left corner like in Scala 3 API documentation. Extra dependencies and their version used for examples are now available on their page. See this page for example.
Contributors
Full Changelog: v2.2.0-RC3...v2.2.0