diff --git a/main/src/io/github/iltotore/iron/RefinedTypeOps.scala b/main/src/io/github/iltotore/iron/RefinedTypeOps.scala index eacbe207..34bbaab9 100644 --- a/main/src/io/github/iltotore/iron/RefinedTypeOps.scala +++ b/main/src/io/github/iltotore/iron/RefinedTypeOps.scala @@ -25,6 +25,9 @@ class RefinedTypeOpsImpl[A, C, T]: */ inline def assume(value: A): T = value.assume[C].asInstanceOf[T] + extension (wrapper: T) + inline def value: IronType[A, C] = wrapper.asInstanceOf[IronType[A, C]] + extension [A, C, T](ops: RefinedTypeOpsImpl[A, C, T]) /** diff --git a/main/test/src/io/github/iltotore/iron/testing/RefinedOpsSuite.scala b/main/test/src/io/github/iltotore/iron/testing/RefinedOpsSuite.scala index fb6a0fe5..5bc9b294 100644 --- a/main/test/src/io/github/iltotore/iron/testing/RefinedOpsSuite.scala +++ b/main/test/src/io/github/iltotore/iron/testing/RefinedOpsSuite.scala @@ -18,6 +18,14 @@ object RefinedTypeOpsSuite extends TestSuite: compileError("Temperature(-100)") } + test("value") { + val t1 = Temperature(100) + val t2 = Temperature(100) + + val result = t1.value + t2.value + assert(result == 200.0) + } + test("re-eval") { val x: Double :| Positive = 5.0 val y: Double :| Greater[10] = 15.0