praxis

Various programming exercises.
git clone git://git.jtobin.io/praxis.git
Log | Files | Refs

Ordered.hs (362B)


      1 
      2 module Ordered where
      3 
      4 import Data.Function (on)
      5 import Data.List (sort, maximumBy)
      6 
      7 longestOrdered :: Ord a => [[a]] -> Maybe [a]
      8 longestOrdered dict = safeMaximumBy (compare `on` length)
      9   [word | word <- dict, sort word == word]
     10 
     11 safeMaximumBy :: (a -> a -> Ordering) -> [a] -> Maybe a
     12 safeMaximumBy _ [] = Nothing
     13 safeMaximumBy p xs = Just (maximumBy p xs)
     14