Created
November 14, 2019 08:30
-
-
Save paxbun/863f659e426f7efb8b7e9ee1f6f9cd6a to your computer and use it in GitHub Desktop.
Split string by space
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
module SplitBySpace (splitBySpace) where | |
splitBySpaceDone :: ([Char], [[Char]]) -> ([Char], [[Char]]) | |
splitBySpaceDone ("", y) = ("", y) | |
splitBySpaceDone (x, y) = ("", [x] ++ y) | |
splitBySpaceAppend :: Char -> ([Char], [[Char]]) -> ([Char], [[Char]]) | |
splitBySpaceAppend a (x, y) = ([a] ++ x, y) | |
splitBySpaceInternal :: [Char] -> ([Char], [[Char]]) | |
splitBySpaceInternal "" = ("", []) | |
splitBySpaceInternal (' ' : xs) = splitBySpaceDone (splitBySpaceInternal xs) | |
splitBySpaceInternal (x : xs) = splitBySpaceAppend x (splitBySpaceInternal xs) | |
splitBySpace :: [Char] -> [[Char]] | |
splitBySpace str = snd (splitBySpaceDone (splitBySpaceInternal str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment