Lambda 几个函数式接口
// predicat.test 输出 true false
public static <T> List<T> Filter(List<T> list, Predicate<T> p){
List<T> result = new ArrayList<T>();
for (T t : list) {
if (p.test(t)) {
result.add(t);
}
}
return result;
}
// consume.accept 返回值 void
public static <T> void foeach(List<T> list, Consumer<T> c){
for (T t : list) {
c.accept(t);
}
}
// function.apply 输入 T 返回 R
public static <T,R> List<R> Map(List<T> list, Function<T, R> f){
List<R> result = new ArrayList<>();
for (T t : list) {
result.add(f.apply(t));
}
return result;
}
@FunctionalInterface
public interface Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get();
}