Paul Fioravanti
September 26, 2019

# Exercism: Bob (Elm)

A presentation outlining my solution to the Exercism Bob problem in Elm (https://exercism.io/tracks/elm/exercises/bob).

Presented at the Sydney Elm meetup on 26 September 2019.

Presentation slide deck markdown and speaker notes (useable in Deckset 2):
https://github.com/paulfioravanti/presentations/tree/master/exercism_elm_bob

## Paul Fioravanti

September 26, 2019

## Transcript

2. None
3. None

5. None
6. None

9. ### ! "Sure." ! "Whoa, chill out!" ! "Calm down, I

know what I'm doing!"
10. ### ! "Sure." ! "Whoa, chill out!" ! "Calm down, I

know what I'm doing!" ! "Fine. Be that way!"
11. ### ! "Sure." ! "Whoa, chill out!" ! "Calm down, I

know what I'm doing!" ! "Fine. Be that way!" ! "Whatever."

16. ### Bob ! Dis\$nguish ques\$ons ! Dis\$nguish yelling ! Dis\$nguish a

ques\$on yelled
17. ### Bob ! Dis\$nguish ques\$ons ! Dis\$nguish yelling ! Dis\$nguish a

ques\$on yelled ! Understand silence
18. ### Bob ! Dis\$nguish ques\$ons ! Dis\$nguish yelling ! Dis\$nguish a

ques\$on yelled ! Understand silence ! Provide a fallback

message =
21. ### Dis\$nguish Silence hey : String -> String hey message =

if isSilence message then "Fine. Be that way!"
22. ### Dis\$nguish Silence hey : String -> String hey message =

if isSilence message then "Fine. Be that way!" isSilence : String -> Bool isSilence message = String.trim message == ""
23. ### Dis\$nguish a Ques\$on Yelled hey : String -> String hey

message = if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!"
24. ### Dis\$nguish a Ques\$on Yelled hey : String -> String hey

message = if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" isYelling : String -> Bool isYelling message = (String.toUpper message == message)
25. ### Dis\$nguish a Ques\$on Yelled hey : String -> String hey

message = if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" isYelling : String -> Bool isYelling message = (String.toUpper message == message) && not (onlyDigitsOrNonWords message)
26. ### Dis\$nguish a Ques\$on Yelled isYelling : String -> Bool isYelling

message = (String.toUpper message == message) && not (onlyDigitsOrNonWords message) onlyDigitsOrNonWords : String -> Bool onlyDigitsOrNonWords message = let regex = "^([0-9]|[^a-zA-Z])+\$" |> Regex.fromString |> Maybe.withDefault Regex.never in Regex.contains regex message
27. ### Dis\$nguish a Ques\$on Yelled hey : String -> String hey

message = if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!"
28. ### Dis\$nguish a Ques\$on Yelled hey : String -> String hey

message = if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" isQuestion : String -> Bool isQuestion message = message |> String.trim |> String.endsWith "?"
29. ### Dis\$nguish Yelled Ques\$on hey : String -> String hey message

= if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!"
30. ### Dis\$nguish Yelling hey : String -> String hey message =

if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" else if isYelling message then "Whoa, chill out!"
31. ### Dis\$nguish Ques\$ons hey : String -> String hey message =

if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" else if isYelling message then "Whoa, chill out!" else if isQuestion message then "Sure."
32. ### Provide a Fallback hey : String -> String hey message

= if isSilence message then "Fine. Be that way!" else if isYelling message && isQuestion message then "Calm down, I know what I'm doing!" else if isYelling message then "Whoa, chill out!" else if isQuestion message then "Sure." else "Whatever."
33. None
34. None
35. None

39. None

42. ### ! Repe\$\$on in condi\$on checking ! Repe\$\$on with String.trim !

Do we really need a regex?
43. ### ! Repe\$\$on in condi\$on checking ! Repe\$\$on with String.trim !

Do we really need a regex? ! Big if statements don't feel right

46. ### Dis\$nguish Silence hey : String -> String hey input =

let message = String.trim input
47. ### Dis\$nguish Silence hey : String -> String hey input =

let message = String.trim input isSilence = message == ""
48. ### Dis\$nguish Silence hey : String -> String hey input =

let message = String.trim input isSilence = message == "" in if isSilence then "Fine. Be that way!" else respondToVerbalMessage message

50. ### Dis\$nguish Ques\$on respondToVerbalRemark : String -> String respondToVerbalRemark message =

let isQuestion = String.endsWith "?" message
51. ### Dis\$nguish Ques\$on respondToVerbalRemark : String -> String respondToVerbalRemark message =

let isQuestion = String.endsWith "?" message hasLetters = String.any Char.isAlpha message
52. ### Dis\$nguish Yelling respondToVerbalRemark : String -> String respondToVerbalRemark message =

let isQuestion = String.endsWith "?" message hasLetters = String.any Char.isAlpha message isYelling = hasLetters && String.toUpper message == message
53. ### Dis\$nguish Ques\$on/Yelling Combos respondToVerbalRemark : String -> String respondToVerbalRemark message

= let -- ... in case ( isQuestion, isYelling ) of
54. ### Dis\$nguish Ques\$on/Yelling Combos respondToVerbalRemark : String -> String respondToVerbalRemark message

= case ( isQuestion, isYelling ) of ( True, True ) -> "Calm down, I know what I'm doing!"
55. ### Dis\$nguish Ques\$on/Yelling Combos respondToVerbalRemark : String -> String respondToVerbalRemark message

= case ( isQuestion, isYelling ) of ( True, True ) -> "Calm down, I know what I'm doing!" ( True, False ) -> "Sure."
56. ### Dis\$nguish Ques\$on/Yelling Combos respondToVerbalRemark : String -> String respondToVerbalRemark message

= case ( isQuestion, isYelling ) of ( True, True ) -> "Calm down, I know what I'm doing!" ( True, False ) -> "Sure." ( False, True ) -> "Whoa, chill out!"
57. ### Dis\$nguish Ques\$on/Yelling Combos respondToVerbalRemark : String -> String respondToVerbalRemark message

= case ( isQuestion, isYelling ) of ( True, True ) -> "Calm down, I know what I'm doing!" ( True, False ) -> "Sure." ( False, True ) -> "Whoa, chill out!" ( False, False ) -> "Whatever."
58. None