No, it has been worked the way GP wrote since approximately forever.
val str: Function[String, String] = s => if (s.length > 3) s else null
val num: Function[String, Integer] = s => if (s == null) -1 else s.length
With Optional, you receive different results depending on whether you call map twice, or combine the functions first: scala> Optional.of("Foo").map[String](str).map[Integer](num)
res12: java.util.Optional[Integer] = Optional.empty
scala> Optional.of("Foo").map[Integer](str.andThen(num))
res15: java.util.Optional[Integer] = Optional[-1]
This is incorrect and violates the functor law. This problem was coined by Paul Graham as the "blub paradox":
you can only notice inferior languages, abstractions and
paradigms to what you currently know, but you can't easily
notice superior ones, unless you make an effort to learn more. (value, no error)
(value, error)
(no value, error)
(no value, no error) (int64, error)
gives you exactly four possibilities.