Exercises:
-
Write a function called
parsePhoneNumber
that takes as an argumentphoneNumber: String
and returns aOption[String]
representing a phone number. Why might we want to useString
here and notInt
? -
Write a better
max
function that returns anOption[Int]
given an argument of typeList[Int]
. How would you write this for a list ofString
? How about aList[Boolean]
? Would the implementations differ in any meaninful way? -
Define a case class
User
that represent a user in our imaginary app. AUser
should have anid
aname
and an optionalemail
. -
Create a list of
Users
- call itusers
- that contains 2User
s. Let's pretend that this is some database of users for our app.