Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #189 Filter and transform list

Produce a new list y containing the result of the function T applied to all elements e of the list x that match the predicate P.

import java.util.stream.Collectors;
x.stream().filter(P).map(T).collect(Collectors.toList());
import java.util.List;
List<T> y = x.stream()
             .filter(P)
             .map(T)
             .toList();
(def y 
  (eduction (filter P)
            (map T))
            x)

New implementation...