Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Last active December 4, 2020 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dminuoso/1dae6372dc8df57e780899759f9156ed to your computer and use it in GitHub Desktop.
Save dminuoso/1dae6372dc8df57e780899759f9156ed to your computer and use it in GitHub Desktop.
-- | Split into strictly monotone slices
strictlyMonotone :: Ord a => [a] -> [[a]]
strictlyMonotone [] = []
strictlyMonotone (x:xs) = go [x] xs
where
go buf [] = []
go bs@(b:_) (x:xs) | x > b
= go (x:bs) xs
| otherwise
= reverse bs : go [x] xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment