lambda-dev Digest, Vol 15, Issue 20 [reduce method result type]

Rémi Forax forax at univ-mlv.fr
Tue Mar 8 05:43:49 PST 2011


  Le 08/03/2011 14:31, Jim Mayer a écrit :
> // I can tolerate this one
>      long product(List<Integer>  list) {
>        return list.map(#{x ->  (long) x}).reduce(0L, #{sum, x ->  sum * x});
>      }

I prefer this one:

   long product(List<Integer>  list) {
       return list.lazy().map(#{x ->  (long) x}).reduce(0L, #{sum, x ->  sum * x});
   }

lazy() means, don't do map directly, but wait and do map and reduce in 
one iteration.

Rémi



More information about the lambda-dev mailing list