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

Popular posts from this blog

Cursor error with postgresql, pgpool and php -

delphi - ESC/P programming! -

c++ - error: use of deleted function -