Created
December 7, 2014 16:32
-
-
Save ashaindlin/3394f7b6923fa03e92ea to your computer and use it in GitHub Desktop.
groupBy with a fold
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
myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]] | |
myGroupBy p xs = foldr f v xs | |
where | |
v = [] | |
f x ys = if (length ys > 0 && p x (head (head ys))) | |
then (x:(head ys)):(tail ys) | |
else [x]:ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare with the official definition. Honestly, I don't think this is too bad.