title: For comprehension and number of function creation
body: <p>Recently I had an interview for Scala Developer position. I was asked such question</p>
  
  <pre><code>// matrix 100x100 (content unimportant)
  
  val matrix = Seq.tabulate(100, 100) { case (x, y) =&gt; x + y }
  
  // A
  
  for {
  
     row &lt;- matrix
  
     elem &lt;- row
  
  } print(elem)
  
  // B
  
  val func = print _
  for {
  
     row &lt;- matrix
  
     elem &lt;- row
  
  } func(elem)
  </code></pre>
  
  <p>and the question was: Which implementation, A or B, is more efficent?</p>
  
  <p>We all know that <em>for comprehensions</em> can be translated to </p>
  
  <pre><code>// A
  
  matrix.foreach(row =&gt; row.foreach(elem =&gt; print(elem)))
  
  // B
  
  matrix.foreach(row =&gt; row.foreach(func))
  </code></pre>
  
  <p>B can be written as <code>matrix.foreach(row =&gt; row.foreach(print _))</code> </p>
  
  <p>Supposedly correct answer is B, because A will create function <code>print</code> 100 times more. </p>
  
  <p>I have checked Language Specification but still fail to understand the answer. Can somebody explain this to me?</p>