Design for collections upgrades
Rémi Forax
forax at univ-mlv.fr
Tue Mar 8 13:26:02 PST 2011
On 03/08/2011 10:24 PM, Brian Goetz wrote:
>>> Further, I think the choice of eager/lazy is a reasonable one to give
>>> the programmer. Programmers who do not need the features offered by
>>> laziness shouldn't need to learn how laziness works just to use the new
>>> collection operations.
>>
>> I don't see the need of having a eager filter().
>
> Java programs have lots of code that basically looks like this:
>
> ArrayList<T> filtered = new ArrayList<T>();
> for (T t : otherList)
> if (predicate(t))
> filtered.add(t);
>
> This can be replaced by the one liner:
>
> ArrayList<T> filtered = otherList.filter(predicate);
>
> Not only is it shorter, it is clearer, less error-prone, and does not
> force the programmer to use side effects to do the computation.
>
Is this one will also works ?
LinkedList<T> filtered = otherList.filter(predicate);
Rémi
More information about the lambda-dev
mailing list