Exercise: Practicing Utility Methods from the Optional Library
Use the Option type and some of its methods.
We'll cover the following
Use the Option
type
Now, it’s your turn!
Let’s practice using the Option
type and some of its methods. For this exercise, fill in the PrintReport()
method to show all the TV shows we have in our catalog. This time, instead of a Movie
class, we have a TvShow
class. Each TV show has a name, rating, creator, and start and end dates. And each creator has a name and a last award name.
Before jumping into the exercise, let’s cover three utility methods from the Optional
library: Match()
, MatchSome()
, and MatchNone()
. These three methods might be handy when solving the exercise.
With the Match()
method, we can evaluate a function on either value of the Option
. And with MatchSome()
and MatchNone()
, we can run a side effect with the Option
having a value and with it not having one, respectively.
For example:
Get hands-on with 1400+ tech skills courses.