better-monadic-for icon indicating copy to clipboard operation
better-monadic-for copied to clipboard

For-comp with no yield should use .foreach

Open japgolly opened this issue 4 years ago • 0 comments

reproduction steps

Desugar the following:

for {x <- List(1); y = 1} ()

problem

It effectively desugars to:

List(1).map { x => val y = 1; (x, y) }.foreach { case (x, y) => () }

expectation

Because there's no yield, I expect all .flatMap and .map calls to be .foreach instead. It should desugar to:

List(1).foreach { x => val y = 1; () }

japgolly avatar Apr 23 '20 10:04 japgolly