RosettaCodeData/Task/Optional-parameters/Groovy/optional-parameters-1.groovy

4 lines
205 B
Groovy

def orderedSort(Collection table, column = 0, reverse = false, ordering = {x, y -> x <=> y } as Comparator) {
table.sort(false) { x, y -> (reverse ? -1 : 1) * ordering.compare(x[column], y[column])}
}