Add 'key function' overloads for iterator.[min, max, min_max]
irh opened this issue · 1 comments
irh commented
The iterator.[min, max, min_max]
functions would benefit from having optional 'key' functions, where the result of calling the function with the iterator's output is used in comparisons. A key overload is already available for list.sort
.
x =
foo: 42
bar: 99
baz: -1
# What I would like to write:
# max_key, max_value = x.max |(_, value)| value
# But instead I have to write something like:
max_value = x.each(|(key, value)| value).max()
max_key, _ = x.get_index x.position |(key, value)| value == max_value
io.print "Entry with maximum value in x is $max_key: $max_value"
# Entry with maximum value in x is bar: 99