getOrElse
GetOrElse is a method used in functional programming to provide a fallback value when a value is missing. In the Scala standard library, getOrElse is defined on the Option[T] type and is commonly used to handle optional values without throwing exceptions.
For an Option[A], the signature is def getOrElse[B >: A](or: => B): B. The method returns the contained
Examples illustrate its typical use. val x: Option[Int] = Some(3); x.getOrElse(0) yields 3. val y: Option[Int] = None;
Relation to other constructs: getOrElse complements map and flatMap for transforming options, and pairs with orElse
Notes: The by-name default enables lazy evaluation, which is important when the default is expensive to compute