File tree Expand file tree Collapse file tree 4 files changed +11
-5
lines changed
examples/success-standard/src Expand file tree Collapse file tree 4 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ Bob answers 'Sure.' if you ask him a question.
6
6
7
7
He answers 'Whoa, chill out!' if you yell at him.
8
8
9
+ He answers 'Calm down, I know what I'm doing!' if you yell a question at him.
10
+
9
11
He says 'Fine. Be that way!' if you address him without actually saying
10
12
anything.
11
13
Original file line number Diff line number Diff line change 1
1
module Bob (responseFor ) where
2
2
import Data.Char (isSpace , isUpper , isAlpha )
3
3
4
- data Prompt = Silence | Yell | Question | Other
4
+ data Prompt = Silence | YellQuestion | Yell | Question | Other
5
5
6
6
classify :: String -> Prompt
7
7
classify s | all isSpace s = Silence
8
- | any isAlpha s && all isUpper (filter isAlpha s) = Yell
9
- | ' ?' == last (filter (not . isSpace) s) = Question
8
+ | yell && question = YellQuestion
9
+ | yell = Yell
10
+ | question = Question
10
11
| otherwise = Other
12
+ where yell = any isAlpha s && all isUpper (filter isAlpha s)
13
+ question = ' ?' == last (filter (not . isSpace) s)
11
14
12
15
response :: Prompt -> String
13
16
response Silence = " Fine. Be that way!"
17
+ response YellQuestion = " Calm down, I know what I'm doing!"
14
18
response Yell = " Whoa, chill out!"
15
19
response Question = " Sure."
16
20
response Other = " Whatever."
Original file line number Diff line number Diff line change 1
1
name : bob
2
- version : 1.0 .0.3
2
+ version : 1.1 .0.4
3
3
4
4
dependencies :
5
5
- base
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ cases = [ Case { description = "stating something"
54
54
}
55
55
, Case { description = " forceful question"
56
56
, input = " WHAT THE HELL WERE YOU THINKING?"
57
- , expected = " Whoa, chill out !"
57
+ , expected = " Calm down, I know what I'm doing !"
58
58
}
59
59
, Case { description = " shouting numbers"
60
60
, input = " 1, 2, 3 GO!"
You can’t perform that action at this time.
0 commit comments