Created
May 11, 2020 16:28
-
-
Save lgastako/75ca3e4877af65e4111ebc4f9a19e2e8 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
words'' :: String -> [String] | |
words'' s | |
| s == "" = [] | |
| otherwise = takeWhile (/= ' ') s : words'' (dropWhile (== ' ') (dropWhile (/= ' ') s)) | |
words' :: String -> [String] | |
words' s | |
| w /= "" = w : words' rest | |
| otherwise = [] | |
where | |
w = takeWhile (/= ' ') . dropWhile (== ' ') $ s | |
rest = dropWhile (/= ' ') . dropWhile (== ' ') $ s | |
demo :: (String -> [String]) -> [[String]] | |
demo f = map f | |
[ "" | |
, " " | |
, " " | |
, " abc" | |
, "def " | |
, " ghi" | |
, "jkl " | |
, "mno pqr" | |
, " stu vwx " | |
, " a b cd efg h i " | |
] | |
test :: (String -> [String]) -> Bool | |
test f = demo f == demo words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment