Re: Where has the map method on Optional moved?

Remi Forax forax at univ-mlv.fr
Mon Feb 25 23:19:26 PST 2013


Yes, I vote to remove it because it doesn't map :) well with the java mindset.
That said, we already discuss that and other alternatives are less nice to use, at least until we use the static import trick (as with reducers)



Sent from my Phone

----- Reply message -----
From: "Sam Pullara" <sam at sampullara.com>
To: <lambda-libs-spec-experts at openjdk.java.net>
Subject: Where has the map method on Optional moved?
Date: Tue, Feb 26, 2013 06:16


I've never been comfortable with this. I'm glad Jed is calling it out.
Can we make Optional first class or remove it?

Sam

On Mon, Feb 25, 2013 at 9:12 PM, Jed Wesley-Smith <jed at wesleysmith.io> wrote:
> Hi Paul,
>
> You don't get a choice, it is a (or forms a) monad, you just removed
> the useful methods (map/flatMap aka fmap/bind). This leaves clients to
> implement them (or the functionality) in an ad-hoc and possibly buggy
> form themselves.
>
> It is a monad if there exists some pair of functions:
>
> A -> Option<A>
> Option<A> -> (A -> Option<B>) -> Option<B>
>
> The first is Optional.of, the second is currently:
>
> Optional<A> a = …
> Optional<B> b = …
> Function<A, Optional<B> f = …
> if (a.isPresent) {
>   b = f.apply(a.get());
> } else {
>   b = Optional.empty();
> }
>
> rather than:
>
> Optional<A> a = …
> Function<A, Optional<B> f = …
> final Optional<B> b = a.flatMap(f);
>
> cheers,
> jed.
>
> On 26 February 2013 00:12, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> Hi Dhananjay,
>>
>> It is not missing it was removed.
>>
>> java.util.Optional has a narrower scope that optional things in other languages. We are not trying to shoe-horn in an option monad.
>>
>> Paul.
>>
>> On Feb 23, 2013, at 12:27 AM, Dhananjay Nene <dhananjay.nene at gmail.com> wrote:
>>
>>> It seemed to be there on the Optional class in b61 but is missing now. Is
>>> there some way to run map/flatMap operations on an Optional?
>>>
>>> Thanks
>>> Dhananjay
>>>
>>
>>
>


More information about the lambda-libs-spec-observers mailing list