Not exactly that, but you can use groupBy fst . sort, then the head of the result list is your "minimumsBy" result.
Data.List.minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
https://www.stackage.org/haddock/lts-12.1/base-4.11.1.0/Data-List.html#v:minimumBy
but there are many cases where that's quite unhelpful. Actually what we
want is more like
minimumsBy :: ... => (a -> a -> Ordering) -> t a -> [a]
There can be many distinct minimizers. For example when I want to get the
collection of the youngest people from [(Age, Person)] I want
minimumsBy (compare `on` fst) [(12, alice), (15, balaji), (12, cho)]
to return
[(12, alice), (12, cho)]
Does "minimumsBy" exist somewhere reasonably standard? Hoogle doesn't throw
up anything obvious
https://www.stackage.org/lts-12.1/hoogle?q=%28a+-%3E+a+-%3E+Ordering%29+-%3E+t+a+-%3E+%5Ba%5D
Thanks,
Tom
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
--