Library and Compiler Contributions in Scala 2

A lot can be done with enrichments though.

implicit class ClampingOps[A](underlying: A) {
  def clamp(lowerBound: A, upperBound: A)(implicit n: Numeric[A]): A = n.max(lowerBound, n.min(underlying, upperBound))
}

in a package scala.backports or something like that would accomplish the same, at the cost of import scala.backports._.

1 Like