Where has the map method on Optional moved?
Jed Wesley-Smith
jed at wesleysmith.io
Mon Feb 25 21:12:01 PST 2013
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-dev
mailing list