/** * Applies the function [f] to each element of this collection in iteration * order. */ void forEach(void f(E element)) { for (E element in this) f(element); }
这是forEach的实现,非常的简单。注意这里传入的函数参数 f 的返回值是void。 函数的实现里也没有对f的返回值做任何处理,毕竟人家声明的就是void——无返回值。
/** * Checks whether any element of this iterable satisfies [test]. * * Checks every element in iteration order, and returns `true` if * any of them make [test] return `true`, otherwise returns false. */ bool any(bool test(E element)) { for (E element in this) { if (test(element)) return true; } return false; }