[GHC] #15566: Implement minimumOn, maximumOn to mirror sortOn

GHC ghc-devs at haskell.org
Mon Aug 27 13:09:20 UTC 2018


#15566: Implement minimumOn, maximumOn to mirror sortOn
-------------------------------------+-------------------------------------
        Reporter:  Garciat           |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  Research
                                     |  needed
       Component:  libraries/base    |              Version:  8.5
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Garciat):

 Well, `maximumBy` and `minimumBy` are already partial by their use of
 `Foldable.foldl1`, so I'm thinking it's probably alright to do the more
 obvious:

 {{{#!hs
 import Data.Foldable
 import Data.Function (on)

 maximumOn :: (Foldable t, Ord b) => (a -> b) -> t a -> a
 maximumOn f = maximumBy (compare `on` f)

 minimumOn :: (Foldable t, Ord b) => (a -> b) -> t a -> a
 minimumOn f = minimumBy (compare `on` f)
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15566#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list