Sha256: 655f5c14d406d26cf47a83e190ac2f4e8769c63f4e5f787b46f47f636546f5b2

Contents?: true

Size: 769 Bytes

Versions: 103

Compression:

Stored size: 769 Bytes

Contents

module Bob (responseFor) where
import Data.Char (isSpace, isUpper, isAlpha)

data Prompt = Silence | YellQuestion | Yell | Question | Other

classify :: String -> Prompt
classify s | all isSpace s = Silence
           | yell && question = YellQuestion
           | yell = Yell
           | question = Question
           | otherwise = Other
           where yell = any isAlpha s && all isUpper (filter isAlpha s)
                 question = '?' == last (filter (not . isSpace) s)

response :: Prompt -> String
response Silence = "Fine. Be that way!"
response YellQuestion = "Calm down, I know what I'm doing!"
response Yell = "Whoa, chill out!"
response Question = "Sure."
response Other = "Whatever."

responseFor :: String -> String
responseFor = response . classify

Version data entries

103 entries across 103 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.179 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.178 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.177 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.176 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.175 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.174 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.173 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.172 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.171 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.170 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.169 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.167 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.166 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.165 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.164 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.163 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.162 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.161 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.160 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs