Optional != @Nullable

Zhong Yu zhong.j.yu at gmail.com
Sun Sep 30 12:28:45 PDT 2012


On Sun, Sep 30, 2012 at 3:36 AM, Artur Biesiadowski <abies at adres.pl> wrote:
> On 30/09/2012 10:13, Jed Wesley-Smith wrote:
>>
>> Option<String> address(Session session) {
>>    return optional(
>>      session.getIoSession().getRemoteAddress()
>>    ).flatMap(socketAddress -> optional(socketAddress.getAddress())
>>    ).flatMap(inetAddress -> optional(inetAddress.getHostAddress()));
>> }
>
> Is it really more readable than
>
> return session.getIoSession().getRemoteAddress().?getAddress().?getHostAddress();

elvis(
    elvis(
        remoteAddress,
        InetSocketAddress::getAddressA),
    InetAddress::getHostAddress);

:D


>
> ?
>
> Given java history and existing libraries, I think that repurposing null
> as None, assuming non-null contents of collections for most of
> lambda-empowered libraries/utilities and providing few operators for
> safe traversal (?. and ?: at least) would be a lot more useful solution.
>
> Regards,
> Artur Biesiadowski
>


More information about the lambda-dev mailing list