Created
June 28, 2016 21:11
-
-
Save seantalts/9ce7b7e81a28dbb248eba6fb57fcfa18 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
{-# LANGUAGE ScopedTypeVariables #-} | |
import Data.Maybe | |
swords :: String -> Bool | |
swords "hello" = True | |
swords "my" = True | |
swords "sam" = True | |
swords _ = False | |
check :: (String, String) -> Maybe String | |
check (prefix, suffix) = | |
if swords prefix | |
then if suffix == "" | |
then Just prefix | |
else fmap ((prefix ++ " ") ++) (separate suffix) | |
else Nothing | |
separate :: String -> Maybe String | |
separate "" = Just "" | |
separate s = listToMaybe $ mapMaybe check splits | |
where splits = map (`splitAt` s) [0..length s] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment