Last active
September 17, 2015 14:13
-
-
Save paulolieuthier/4201d8b64d7d88258f8b to your computer and use it in GitHub Desktop.
Haskell: break a list into sublists using a split element
This file contains hidden or 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
-- | |
-- Break a list into sublists using a split element | |
-- Author: Paulo Lieuthier | |
-- | |
wordss :: Eq a => a -> [a] -> [[a]] -> [a] -> [[a]] | |
wordss _ [] acc word = acc ++ [word] | |
wordss sp (x:xs) acc word | |
| x == sp = wordss sp xs (acc ++ [word]) [] | |
| otherwise = wordss sp xs acc (word ++ [x]) | |
words' sp list = wordss sp list [] [] | |
main :: IO () | |
main = do | |
putStrLn $ show $ words' 1 [2, 3, 1, 4, 4, 1, 5, 4, 1, 4] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment