def optionAdd(x:Option[Int], y:Option[Int]):Option[Int] =
for(xx <- x; yy <- y) yield xx+yy
I don't dare wasting time with the java version, specially because someone greatly smarter than me already did http://functionaljava.org/examples/1.5/#Option.bind. The example in link is doing basically what optionAdd
does in a infinitely less concise way.