Skip to content

Instantly share code, notes, and snippets.

@paulolieuthier
Last active September 17, 2015 14:13
Show Gist options
  • Save paulolieuthier/4201d8b64d7d88258f8b to your computer and use it in GitHub Desktop.
Save paulolieuthier/4201d8b64d7d88258f8b to your computer and use it in GitHub Desktop.
Haskell: break a list into sublists using a split element
--
-- 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