源码
// Actions (launch a job to return a value to the user program)
/**
* Applies a function f to all elements of this RDD.
* 作用一个函数到RDD的所有元素。
*/
def foreach(f: T => Unit): Unit = withScope {
val cleanF = sc.clean(f)
sc.runJob(this, (iter: Iterator[T]) => iter.foreach(cleanF))
}
/**
* Applies a function f to each partition of this RDD.
* 作用一个函数到RDD的每个分区。
*/
def foreachPartition(f: Iterator[T] => Unit): Unit