elm/exercises/bob/Bob.example

47 lines
778 B
Text
Raw Normal View History

2016-03-15 18:25:14 +00:00
module Bob (..) where
2016-02-27 17:45:34 +00:00
import String
import Regex
hey : String -> String
hey remark =
if isShouting remark then
"Whoa, chill out!"
else if isQuestion remark then
"Sure."
else if isSilence remark then
"Fine. Be that way!"
else
"Whatever."
isShouting : String -> Bool
isShouting remark =
isUppercase remark && hasCharacters remark
isUppercase : String -> Bool
isUppercase remark =
remark == String.toUpper remark
isQuestion : String -> Bool
isQuestion remark =
String.endsWith "?" remark
hasCharacters : String -> Bool
hasCharacters remark =
Regex.contains characterRegex remark
characterRegex : Regex.Regex
characterRegex =
Regex.regex "[a-zA-Z]"
isSilence : String -> Bool
isSilence remark =
String.isEmpty (String.trim remark)