Is it possible to extract the bounds from the predicate/witness of a Refined variable at runtime? Something like the following.
// Should return L as a Double
def getLowerBound[L, H](v: Refined[Double, Interval.Closed[L, H]]): Double = ???
val v: Refined[Double, Interval.Closed[0.5, 1.0]] = 0.94
val lowerBound = getLowerBound(v)
lowerBound shouldBe 0.5
You can use a type bound to tell the compiler
L
will be aDouble
and then use theValueOf
typeclass to extract the value of the literal type; like this:You can see the code running here.