Option
should only return Some
or None
SC-T1005Methods with return type Option
should either return Some
if a suitable value exists or None
if not. Returning null
from such methods can have unintended side effects.
val elements = List(1, 2, 3, 4, 5)
val lastElement = elements.lastOption // Some(5)
val elements = List()
val lastElement = elements.lastOption // None