[ https://issues.apache.org/jira/browse/SPARK-16694?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15390982#comment-15390982 ]
Apache Spark commented on SPARK-16694: -------------------------------------- User 'srowen' has created a pull request for this issue: https://github.com/apache/spark/pull/14332 > Use for/foreach rather than map for Unit expressions whose side effects are > required > ------------------------------------------------------------------------------------ > > Key: SPARK-16694 > URL: https://issues.apache.org/jira/browse/SPARK-16694 > Project: Spark > Issue Type: Improvement > Components: Examples, MLlib, Spark Core, SQL, Streaming > Reporter: Sean Owen > Assignee: Sean Owen > Priority: Minor > > {{map}} is misused in many places where {{foreach}} is intended. This caused > a bug in https://issues.apache.org/jira/browse/SPARK-16664 and might be a > latent bug elsewhere; it's also easy to find with IJ inspections. Worth > patching up. > To illustrate the general problem, {{map}} happens to work in Scala where the > collection isn't lazy, but will fail to execute the code when it is. {{map}} > also causes a collection of {{Unit}} to be created pointlessly. > {code} > scala> val foo = Seq(1,2,3) > foo: Seq[Int] = List(1, 2, 3) > scala> foo.map(println) > 1 > 2 > 3 > res0: Seq[Unit] = List((), (), ()) > scala> foo.view.map(println) > res1: scala.collection.SeqView[Unit,Seq[_]] = SeqViewM(...) > scala> foo.view.foreach(println) > 1 > 2 > 3 > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org