Skip to content

Instantly share code, notes, and snippets.

@evansb
Created June 21, 2014 14:16
Show Gist options
  • Save evansb/443facb5d2bc1a42840d to your computer and use it in GitHub Desktop.
Save evansb/443facb5d2bc1a42840d to your computer and use it in GitHub Desktop.
Some interesting fold example
-- 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