@@ -1804,7 +1804,7 @@ object desugar {
18041804 /** Create tree for for-comprehension `<for (enums) do body>` or
18051805 * `<for (enums) yield body>` where mapName and flatMapName are chosen
18061806 * corresponding to whether this is a for-do or a for-yield.
1807- * The creation performs the following rewrite rules:
1807+ * If betterFors are enabled, the creation performs the following rewrite rules:
18081808 *
18091809 * 1.
18101810 *
@@ -1872,6 +1872,46 @@ object desugar {
18721872 * (Where empty for-comprehensions are excluded by the parser)
18731873 *
18741874 * If the aliases are not followed by a guard, otherwise an error.
1875+ *
1876+ * With betterFors disabled, the translation is as follows:
1877+ *
1878+ * 1.
1879+ *
1880+ * for (P <- G) E ==> G.foreach (P => E)
1881+ *
1882+ * Here and in the following (P => E) is interpreted as the function (P => E)
1883+ * if P is a variable pattern and as the partial function { case P => E } otherwise.
1884+ *
1885+ * 2.
1886+ *
1887+ * for (P <- G) yield E ==> G.map (P => E)
1888+ *
1889+ * 3.
1890+ *
1891+ * for (P_1 <- G_1; P_2 <- G_2; ...) ...
1892+ * ==>
1893+ * G_1.flatMap (P_1 => for (P_2 <- G_2; ...) ...)
1894+ *
1895+ * 4.
1896+ *
1897+ * for (P <- G; E; ...) ...
1898+ * =>
1899+ * for (P <- G.filter (P => E); ...) ...
1900+ *
1901+ * 5. For any N:
1902+ *
1903+ * for (P_1 <- G; P_2 = E_2; val P_N = E_N; ...)
1904+ * ==>
1905+ * for (TupleN(P_1, P_2, ... P_N) <-
1906+ * for (x_1 @ P_1 <- G) yield {
1907+ * val x_2 @ P_2 = E_2
1908+ * ...
1909+ * val x_N & P_N = E_N
1910+ * TupleN(x_1, ..., x_N)
1911+ * } ...)
1912+ *
1913+ * If any of the P_i are variable patterns, the corresponding `x_i @ P_i` is not generated
1914+ * and the variable constituting P_i is used instead of x_i
18751915 *
18761916 * @param mapName The name to be used for maps (either map or foreach)
18771917 * @param flatMapName The name to be used for flatMaps (either flatMap or foreach)
0 commit comments