RFR 8080418 Add Optional.or()

Tagir F. Valeev amaembo at gmail.com
Sat Sep 26 08:32:49 UTC 2015


Hello!

>> Quite interesting and long awaited features (at least according to
>> StackOverflow questions).

PS> All of them? or just the first?

The first one is definitely the most requested feature. However,
additional methods for primitive optionals were requested at least
twice:
http://stackoverflow.com/q/29104968/4856258
http://stackoverflow.com/q/23414903/4856258

Something like mapOrElseGet was implicitly requested here
(though it's more look like ifPresentOrElse)
http://stackoverflow.com/q/23773024/4856258

>> Isn't it a good idea to provide also a way
>> to transfer between Optional types like "mapToInt", "mapToObj", etc.,
>> like it's done in Stream API?
>> 

PS> I don’t wanna go there, my response is transform Optional* into a
PS> *Stream. An argument for adding mapOrElseGet (notice that the
PS> primitive variants return U) is that other functionality can be composed from it.

Probably then it's better instead of adding map, filter, etc. just add
single "boxed()" method to convert OptionalDouble to Optional<Double>,
etc.? So if somebody really wants to chain optional calls, let them do
the boxing and use the features of normal Optional.

With best regards,
Tagir Valeev.




More information about the core-libs-dev mailing list