For-comprehension with None

Report a typo

You know that for-comprehension can be used for Option. What happens if it is applied to None?

def countNonEmptyLength(stringOpt: Option[String]): Option[Int] =
  for
    string <- stringOpt
    if string.nonEmpty
  yield string.size


countNonEmptyLength(None)
Select one option from the list
___

Create a free account to access the full topic