I feel like something is missing from the available minimum functions. I’ve come across the issue multiple times where i want to get the value of a collection that gives the minimum value of a specified function. i.e. I want to specify my own comparator.
min returns the smallest value in a collection (or the arguments). I assume comparison is done by isless. I guess I could overload isless but that seems heavy-handed for a one-time minimisation.
minimum also finds the smallest value in a collection. It also provides a method minimum(f, itr) which returns the smallest result of calling f on itr. This is close, but it returns the minimum value of f, not the value of itr that gives the value of f
argmin returns the index of the smallest element, which is helpful, but again doesn’t allow specifying a custom comparator.
So far I’ve been solving this with the below function, but this seems like it might be something that already exists elsewhere.