I’m rewriting some sorting functions at work.
All sorting functions require that the subject be first then non listings and then listings.
I’m trying to produce an elegant solution so i created a base sort function called sort.
The problem I’m facing is that occasionally I need to reverse the result of v. Hence where i added reverseV: Boolean = false
to the base function
But that’s where I got lost.
Any ideas on how to reverse _.closeDate
? Either in the closeDate function or in the base function using the flag as I started to do?
Thanks
object PropertySort {
//false is less than thus goes to the left
def sort(v: Property => Any, reverseV: Boolean = false)(implicit ps: Seq[Property]): Seq[Property] = ps.sortBy(p => (!p.isSubject, p.isListing, v))
def salesPrice(ps: Seq[Property]): Seq[Property] = sort(_.salesPrice)
def closeDate(ps: Seq[Property]): Seq[Property] = sort(_.closeDate)
}