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.119 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.118 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.117 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.116 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.115 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.114 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.113 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.111 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.110 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.109 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.108 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.107 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.106 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.105 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.104 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.103 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.102 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.101 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.100 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs
trackler-2.2.1.99 tracks/haskell/exercises/bob/examples/success-standard/src/Bob.hs