Skip to content

Commit

Permalink
feat: Access inner value via RefinedTypeOps extension (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkw authored May 26, 2023
1 parent 760c30c commit b401ea6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main/src/io/github/iltotore/iron/RefinedTypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b401ea6

Please sign in to comment.