资 源 简 介
The map, filter and reduce functions allow working with lists very conveniently. They are known from functional programming. This library brings them to Java.
Sample code:
```
List list = Arrays.asList("1", "2", "3", "4", "5", "6", "7");
System.out.println("List of Strings: " + list);
// map: String to Integer
Collection list2 = new Mapping() {
public Integer function(String s) {
return Integer.valueOf(s);
}
}.apply(list);
System.out.println("List of Integers: " + list2);
// filter: even numbers
Collection list3 = new Filter() {
public Boolean function(Integer s) {
return s % 2 == 0;
}
}.apply(list2);
System.out.println("Filtered even: " + list3);
// map with closure: divide every value by 2
final int divisor = 2;
Collection list4 = new Mapping() {