Last active
November 21, 2017 18:18
-
-
Save emanon-was/693ac585e47ba3aa694be2fb350eb091 to your computer and use it in GitHub Desktop.
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
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