I would like to do a generic function able to sort different nested case classes by one of their "sub" argument in common.
For the moment I have done this:
sealed trait SortableByGeoPoint {
val geographicPoint: Int
}
case class A(id: Int, geographicPoint: Int) extends SortableByGeoPoint
case class B(image: String, geographicPoint: Int) extends SortableByGeoPoint
case class C(a: A, other: String)
case class D(b: B, other: Int)
def sortByGeoPoint(sequence: Seq[SortableByGeoPoint]): Seq[SortableByGeoPoint] = sequence.sortBy(_.geographicPoint)
It works well to sort a sequence of class A or class B, but I would like to make it work for a case class C or D (that contain a SortableByGeoPoint sub-class) How can I accomplish this?
I took a look at shapeless but didn't find a way to do this, but any way to do it (knowing that I will add later other classes like the class C or D), would be perfect.