Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.0-beta-8
-
None
-
None
Description
It would be great to have an alternate form of min()/max() where closure returns a value to be compared, rather than a comparison. I'm often trying to choose the "most desirable" element of a list, and I have some expression that computes the desirability. Right now I have to do:
mylist.max
{x,y | my_desirability_expression(x) <=> my_desirability_expression(y) }That's wordy because I need to write the desirability expression twice, and I also need to have explicit arguments for the closure. It would be great if there were a "maxv" where I could write:
mylist.maxv
{ my_desirability_expression(it) }
maxv for "maximum of value." Similarly with minv.
This is trivial to implement; here's what I use (a global function):
def minv (l, Closure f) {
return l.min
}