Scala best practice: How to use the Option/Some/None pattern
This is an excerpt from the 1st Edition of the Scala Cookbook (partially modified for the internet). This is Recipe 20.6, “Scala best practice: How to use the Option/Some/None pattern.”
Problem
For a variety of reasons, including removing null
values from your Scala code, you want to use what I call the Option/Some/None pattern. Or, if you’re interested in a problem (exception) that occurred while processing code, you may want to return Try/Success/Failure from a method instead of Option/Some/None.