title: Why does foreach not bring anything to the driver program?
body: <p>I wrote this program in spark shell</p>
  
  <pre><code>val array = sc.parallelize(List(1, 2, 3, 4))
  array.foreach(x =&gt; println(x))
  </code></pre>
  
  <p>this prints some debug statements but not the actual numbers.</p>
  
  <p>The code below works fine</p>
  
  <pre><code>for(num &lt;- array.take(4)) {
    println(num)
  }
  </code></pre>
  
  <p>I do understand that <code>take</code> is an action and therefore will cause spark to trigger the lazy computation.</p>
  
  <p>But foreach should have worked the same way... why did <code>foreach</code> not bring anything back from spark and start doing the actual processing (get out of lazy mode)</p>
  
  <p>How can I make the foreach on the rdd work?</p>