Scala for comprehension - tackling null -


in snippet below:

 {   strval  <- str   longval <- str.strtolong  } yield longval 

where str option[string]. if str comes in some(null)? how handle in comprehension?

i think dealing some(null) because used constructor in code. try option(variablewithnull) , result none. operations none have result of none instead of annoying java.lang.nullpointerexception.

perhaps use code:

val str: option[string] = option(null) str.fold(0l) {_.tolong} 

Comments