Groovy has the spaceship operator <=>
which provides an easy way to implement comparisons. How can I chain it in a groovier way then the code below? In this example I want to compare the items by price first and then by name if both have the same price.
class Item implements Comparable {
int price
String name
int compareTo(Item other) {
int result = price <=> other.price
if (result == 0) {
result = name <=> other.name
}
return result
}
}