I have an object with a bunch of related routines and all their declarations look the same, something like
object Sorting {
def qsort[a <% Ordered[a]] ....
def partition[a <% Ordered[a]] ...
def qselect[a <% Ordered[a]] ...
}
Is there a way to specify the type constraint in one place and reduce declarations to something like qsort[a](xs: Stream[a])
or even better just qsort(xs: Stream[a])
?
For the time being I've decided to roll with implicit classes
object Implicits {
implicit class SortableArray[a <% Ordered[a]](xs: Array[a]) {
def qsort = {...}
}
}
object Application {
import Implicits._
def main(args: Array[String]) = {
val xs = Array(1,2,3)
xs.qsort
}
}