Last active
August 29, 2015 13:57
-
-
Save dripolles/9597057 to your computer and use it in GitHub Desktop.
1HaskellADay 2014/03/17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has a trivial solution:
scanl1 max
which I didn't see. Ouch.