Is there a way to avoid having to wrap a potentially null result inside another option when mapping from an option.
option.flatMap(arg => Option(arg.somePotentiallyNullValue))
Eg something like
option.optionMap(arg => arg.somePotentiallyNullValue )
I just have a lot of Java code in our codebase that means forever wrapping the results of maps in further Option calls.
What about implicit conversion from nullable type to
Option? Declare this somewhere in scope:Later the compiler will figure it out:
Since
flatMapexpectsOption[T]as a result value, compiler usestoOptionimplicit conversion like this: