groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Matz <>
Subject re-using a comparison closure
Date Mon, 16 May 2016 15:28:25 GMT
I have to sort a list of strings based on a number within the string . . .
I am able to sort using something like:
list.sort( { a,b -> getVersion(a) <=> getVersion(b)})

I need to use this in a bunch of places in my code and was hoping to
replace it with a method, like:
list.sort( compareVersions)

with compareVersions:
def compareVersions(a, b) {
  return getVersion(a).toInteger() <=> getVersion(b).toInteger()

putting the method (compoareVersions) into the sort as a param doesn't
work.  Anyone know what I'm missing?


View raw message