Correct.

It's desugared into rdd.foreach() by Scala compiler

--
Oleksiy Dyagilev

On Tue, Jul 12, 2016 at 6:58 PM, philipghu <philguang...@gmail.com> wrote:

> Hi,
>
> I'm new to Spark and Scala as well. I understand that we can use foreach to
> apply a function to each element of an RDD, like rdd.foreach
> (x=>println(x)), but I saw we can also do a for loop to print each element
> of an RDD, like
>
> for (x <- rdd){
> println(x)
> }
>
> Does defining the foreach function in RDD make an RDD traversable like
> this?
> Does the compiler automatically invoke the foreach function when it sees a
> for loop?
>
>
> Thanks!
> Phil
>
>
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/RDD-for-loop-vs-foreach-tp27326.html
> Sent from the Apache Spark User List mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscr...@spark.apache.org
>
>

Reply via email to