@@ -1804,7 +1804,7 @@ object desugar {
1804
1804
/** Create tree for for-comprehension `<for (enums) do body>` or
1805
1805
* `<for (enums) yield body>` where mapName and flatMapName are chosen
1806
1806
* 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:
1808
1808
*
1809
1809
* 1.
1810
1810
*
@@ -1872,6 +1872,46 @@ object desugar {
1872
1872
* (Where empty for-comprehensions are excluded by the parser)
1873
1873
*
1874
1874
* 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
1875
1915
*
1876
1916
* @param mapName The name to be used for maps (either map or foreach)
1877
1917
* @param flatMapName The name to be used for flatMaps (either flatMap or foreach)
0 commit comments