What will be the result of applying fold to Option in the following code?
val number: Option[Int] = Some(3)
val noNumber: Option[Int] = None
val result1 = number.fold(1)(_ * 3)
val result2 = noNumber.fold(1)(_ * 3)

println(result1)
println(result2)
Explanation
fold will extract the value from the Option, or provide a default if the value is None.

Source: Scala Exercises: Options

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Scala
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты