The Hadoop in Real World team contrasts two functions:
foreach() and foreachPartition() are action function and not transform function. Both functions, since they are actions, they don’t return a RDD back.
Read on for the big difference between the two.