Using the Spaceship Operator
I like the Spaceship operator, useful for all sorts of custom sorting scenarios. Some examples of usage are here. One situation in which it's particularly helpful is in creating a comparator on the fly of an object using multiple fields. e.g.
def list = [
[ id:0, first: 'Michael', last: 'Smith', age: 23 ],
[ id:1, first: 'John', last: 'Smith', age: 30 ],
[ id:2, first: 'Michael', last: 'Smith', age: 15 ],
[ id:3, first: 'Michael', last: 'Jones', age: 15 ],
]
// sort list by last name, then first name, then by descending age
assert (list.sort { a,b -> a.last <=> b.last ?: a.first <=> b.first ?: b.age <=> a.age })*.id == [ 3,1,0,2 ]