✅ haskell: bob
This commit is contained in:
17
haskell/bob/examples/success-text/package.yaml
Normal file
17
haskell/bob/examples/success-text/package.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
name: bob
|
||||
|
||||
dependencies:
|
||||
- base
|
||||
- text
|
||||
|
||||
library:
|
||||
exposed-modules: Bob
|
||||
source-dirs: src
|
||||
|
||||
tests:
|
||||
test:
|
||||
main: Tests.hs
|
||||
source-dirs: test
|
||||
dependencies:
|
||||
- bob
|
||||
- hspec
|
19
haskell/bob/examples/success-text/src/Bob.hs
Normal file
19
haskell/bob/examples/success-text/src/Bob.hs
Normal file
@ -0,0 +1,19 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Bob (responseFor) where
|
||||
|
||||
import Data.Char (isSpace, isUpper, isLower)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text (Text)
|
||||
|
||||
responseFor :: Text -> Text
|
||||
responseFor s
|
||||
| isSilent s = "Fine. Be that way!"
|
||||
| isYelling s && isAsking s = "Calm down, I know what I'm doing!"
|
||||
| isYelling s = "Whoa, chill out!"
|
||||
| isAsking s = "Sure."
|
||||
| otherwise = "Whatever."
|
||||
|
||||
isSilent, isYelling, isAsking :: Text -> Bool
|
||||
isSilent = T.all isSpace
|
||||
isYelling = (&&) <$> T.any isUpper <*> T.all (not . isLower)
|
||||
isAsking = (Just '?' ==) . fmap snd . T.unsnoc . T.stripEnd
|
Reference in New Issue
Block a user