From b401ea6e4e28ee7e2f6ad768e24d3b521abb79c6 Mon Sep 17 00:00:00 2001 From: antonkw Date: Thu, 25 May 2023 23:43:02 -0700 Subject: [PATCH] feat: Access inner value via RefinedTypeOps extension (#120) --- main/src/io/github/iltotore/iron/RefinedTypeOps.scala | 3 +++ .../io/github/iltotore/iron/testing/RefinedOpsSuite.scala | 8 ++++++++ 2 files changed, 11 insertions(+) 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