Search code examples
haskellfilteringpointfreetacit-programming

Point-free for filter function


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 = ??

Solution

  • 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.