Skip to content

Instantly share code, notes, and snippets.

@emanon-was
Last active November 21, 2017 18:18
Show Gist options
  • Save emanon-was/693ac585e47ba3aa694be2fb350eb091 to your computer and use it in GitHub Desktop.
Save emanon-was/693ac585e47ba3aa694be2fb350eb091 to your computer and use it in GitHub Desktop.
startWith :: (Eq a) => [a] -> [a] -> Maybe [a]
startWith [] ys = Just ys
startWith xs [] = Nothing
startWith (x:xs) (y:ys)
| x == y = startWith xs ys
| otherwise = Nothing
split :: (Eq a) => [a] -> [a] -> [[a]]
split [] lst = [lst]
split sep lst = split' [] lst
where split' acc [] = [acc]
split' acc (x:xs) =
case startWith sep (x:xs) of
Just ys -> [acc] ++ split' [] ys
Nothing -> split' (acc ++ [x]) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment