Basic map-filter-reduce pattern

???

JDK 7 way

public interface Mapper<T, V> {
public V map(T t) ;
}

public interface Predicate<T> {
public boolean filter(T t) ;
}

public interface Reducer<T> {
public T reduce(T t1, T t2) ;
}

List<Person> persons = … ;
int sum =
persons.map(
new Mapper<Person, Integer>() {
public Integer map(Person p) {
return p.getAge() ;
}
})
.filter(
new Filter<Integer>() {
public boolean filter(Integer age) {
return age > 20 ;
}
})
.reduce(0,
new Reducer<Integer>() {
public Integer reduce(Integer i1, Integer i2) {
return i1 + i2 ;
}
}
}) ;