Skip to content

Instantly share code, notes, and snippets.

@k0001
Created January 2, 2012 09:21
Show Gist options
  • Save k0001/1550005 to your computer and use it in GitHub Desktop.
Save k0001/1550005 to your computer and use it in GitHub Desktop.
My (untested) implementation of Data.List.groupBy
-- My (untested) implementation of Data.List.groupBy
groupBy' :: (a -> a -> Bool) -> [a] -> [[a]]
groupBy' f xs = foldr step [] xs
where step x acc@(yy@(y:ys):yys)
| f x y = (x:yy):yys
| otherwise = [x]:acc
step x [] = [[x]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment