Is this code convertible to a lambda style?
Marcos Antonio
marcos_antonio_ps at hotmail.com
Sun Dec 29 07:13:17 PST 2013
I agree with you. In terms of readibility two filters are better and, as you pointed out, it doesn't hurt performance. Also, as I work with 80 columns in my editor, two filters fit better; with one filter I would have to continue the lambda in the next line.
Marcos
________________________________
> Date: Sun, 29 Dec 2013 14:34:18 +0300
> Subject: Re: Is this code convertible to a lambda style?
> From: pavel.shackih at gmail.com
> To: mcnepp02 at googlemail.com
> CC: marcos_antonio_ps at hotmail.com; lambda-dev at openjdk.java.net
>
> In terms of perfomance first variant can better because under hood
> stream implementation know about 2 predicates and can optimise this
> (for example parallelize) on the fly. Anyway I believe it is hard to
> say about perfomance benefits in this case. Also I think in terms of
> readability two filters looks more elegant and clean but it is a matter
> of taste :)
>
>
> 2013/12/29 Gernot Neppert
> <mcnepp02 at googlemail.com<mailto:mcnepp02 at googlemail.com>>
> Am 28.12.2013 17:00, schrieb Marcos Antonio:
>>
>> Maybe at this point you can call me a little paranoid, but I like a
> code that looks a bit more symmetric (maybe just for aesthetic
> reasons). This is how my code is now:
>>
>> return getMetadataReader().getPropertyDescriptors().stream().
>> filter(d -> d.getType() == PropertyType.ENTITY).
>> filter(d -> hasChildAssociation(d)).
>> findFirst().
>> map(d -> d.convertToProperty()).
>> orElse(null);
>>
>>
>
> Maybe it would benefit (at least in terms of readability, but also
> performance-wise) from combining the two filters like this:
>
> return getMetadataReader().getPropertyDescriptors().stream().
> filter(d -> d.getType() == PropertyType.ENTITY &&
> hasChildAssociation(d)).
> findFirst().
> map(d -> d.convertToProperty()).
> orElse(null);
>
>
>
>
>
>
> --
> Pavel
More information about the lambda-dev
mailing list