Introduction to Scala Part3: Option & Pattern Matching

Bubu
4,429 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Methods of Option

get

Some(1).get // 1
None.get //java.util.NoSuchElementException: None.get

getOrElse

Some(1).getOrElse(2) // 1
None.getOrElse(2) // 2

Option

Option(1) // Some(1)
Option(null) // None

IsEmpty

Some(1).isEmpty // false
None.isEmpty // true

Map Option

getNameOfPerson
getNameUsingMap
getEmail
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content