Skip to content

Instantly share code, notes, and snippets.

@seantalts
Created June 28, 2016 21:11
Show Gist options
  • Save seantalts/9ce7b7e81a28dbb248eba6fb57fcfa18 to your computer and use it in GitHub Desktop.
Save seantalts/9ce7b7e81a28dbb248eba6fb57fcfa18 to your computer and use it in GitHub Desktop.
{-# 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