Skip to content

Instantly share code, notes, and snippets.

@dripolles
Last active August 29, 2015 13:57
Show Gist options
  • Save dripolles/9597057 to your computer and use it in GitHub Desktop.
Save dripolles/9597057 to your computer and use it in GitHub Desktop.
1HaskellADay 2014/03/17
-- http://codepad.org/4ZT5ZCwH
import Control.Applicative
import Control.Arrow
import Data.List
maximumList :: Ord a => [a] -> [a]
maximumList = mapAccumL (\x -> max x &&& max x) <$> head <*> id >>> snd
-- Different approach
maximumList' :: Ord a => [a] -> [a]
maximumList' = groupBy (>=) >>> concatMap (map <$> const . head <*> id)
main = do
let l = [1,2,1,1,3,4,2,2,10,9,8]
print $ maximumList l
print $ maximumList' l
@dripolles
Copy link
Author

This has a trivial solution: scanl1 max which I didn't see. Ouch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment