Groovy Schwartzian Transform -
can suggest simpler, more elegant implementation of perl's schwartzian transform in groovy?
def unsorted = [7, 3, 109, 22, 55] def sortcriterion = { + 1 } def sorted = unsorted.inject([:],{map, v -> map << [(v):sortcriterion(v)]}).sort{it.value}.collect{k,v->k} assert sorted == [ 3, 7, 22, 55, 109]
there must better way keys sorted map, instance.
here's take on it:
def sorted = unsorted.groupby(sortcriterion).sort().values().flatten()
Comments
Post a Comment