Is this code convertible to a lambda style?
Павел Шацких
pavel.shackih at gmail.com
Sun Dec 29 03:34:18 PST 2013
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>
> 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