Does there exist a point-free function for filter function to find minimum of first element of pair in a list? for example:
findMinimum xs = filter ((== minimum (map fst xs)) . fst ) xs
-- example:
findMinimum [(0, 0), (0, 1), (2, 2), (3, 2), (1, 4)] = [(0, 0), (0, 1)]
How to convert findMinimum function to point-free:
findMinimum = ??
pointfree.io outputs this, which is not too bad. I still prefer the original code, though.
findMinimum = filter =<< (. fst) . (==) . minimum . map fst
a different implementation
head . groupBy ((==) `on` fst) . sortOn fst
sort and group by first, pick the first sub list. Perhaps you may want to handle empty list explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With