Created
June 21, 2014 14:16
-
-
Save evansb/443facb5d2bc1a42840d to your computer and use it in GitHub Desktop.
Some interesting fold example
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
-- Try to guess what divide does! | |
divide:: (Integral a) => [a] -> [[a]] | |
divide = f1 . f2 where | |
f1 = foldr f3 [] | |
f2 = map (:[]) | |
f3 x acc | |
| null acc = x : acc | |
| (head x * head (head acc)) > 0 = (x ++ head acc) : tail acc | |
| otherwise = x : acc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment