Poor (or Rich) Man's Refinement Types in Scala 3.x?

opaque type PositiveInt <: Int = Int
def PositiveInt(x: Int): Option[PositiveInt] =
  if x > 0 then Some(x) else None

cf http://dotty.epfl.ch/docs/reference/other-new-features/opaques.html#bounds-for-opaque-type-aliases

1 Like