24 lines
No EOL
672 B
Haskell
24 lines
No EOL
672 B
Haskell
database :: [(Integer, String)]
|
|
database = [(1, "Julie"),
|
|
(2, "Chris"),
|
|
(3, "Alonzo"),
|
|
(4, "Melman")]
|
|
|
|
greetUser :: Integer -> Maybe String
|
|
greetUser record = fmap ("Hello, " ++) ((lookup record database) >>= makeUsername)
|
|
|
|
removeSpaces :: String -> Maybe String
|
|
removeSpaces string =
|
|
case (filter (/= ' ') string) of
|
|
"" -> Nothing
|
|
result -> Just result
|
|
|
|
validateLength :: String -> Maybe String
|
|
validateLength string =
|
|
case (length string > 25) of
|
|
True -> Nothing
|
|
False -> Just string
|
|
|
|
|
|
makeUsername :: String -> Maybe String
|
|
makeUsername string = removeSpaces string >>= validateLength |