How can I sort a Vector of my objects in Scala? Is there some library sorting routines or do I have to write my own?
I have a class:
class Data2D(var x:Int, var y:Int)
and I am passing a vector of these to my function:
private def foo(data: Vector[Data2D]): Int = {
data:Vector sortedOnX = // ??
}
how can I sort the vector, based on the x-values of the Data2D objects?
In java I do:
Collections.sort(data, XComparator.INSTANCE);
where XComparator is:
enum XComparator implements Comparator<Data2D> {
INSTANCE;
@Override
public int compare(Data2D o1, Data2D o2) {
if (o1.getX() <= o2.getX()) {
return -1;
} else {
return 1;
}
}
}