I've enterprise polyglot codebase which is made of java and scala.
We have lot of places where we do map function on Option[T]
and the mapping function is legacy code which returns null.
Option(2).map(x => null)
returns Some(null)
. when another higher order function is applied on the result it throws NullPointerException.
As a workaround we do Option[T](t).map(x => Option(mapping(x)))
in order to make this result None
. It is slowly becoming code smell.
I'm trying to see whether there is any better way to do this or there is scala compiler option that return None
when the calls like this Option[T](t).map(x => null)
are made automagically.