You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/fewer-braces.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ title: SIP-NN Fewer Braces
14
14
|----------------|--------------------|
15
15
| July 1st 2022 | Initial Draft |
16
16
| July 21st 2022 | Expanded Other Conerns Section |
17
+
17
18
## Summary
18
19
19
20
The current state of Scala 3 makes braces optional around blocks and template definitions (i.e. bodies of classes, objects, traits, enums, or givens). This SIP proposes to allow optional braces also for function arguments.
@@ -172,7 +173,7 @@ xs.groupMapReduce: item =>
172
173
173
174
I argue that the language already provides mechanisms to express these examples without having to resort to braces. (Aside: I don't think that resorting to braces occasionally is a bad thing, but some people argue that it is, so it's good to have alternatives). Basically, we have three options
174
175
175
-
- Use parentheses. That always works if the argument is a lambda.
176
+
- Use parentheses.
176
177
- Use an explicit `apply` method call.
177
178
- Use a `locally` call.
178
179
@@ -273,6 +274,15 @@ val y = (xs.map: (Int => Int) =>
273
274
```
274
275
would then not be legal anyway. But it turned out that there were several community projects that were using function types in ascriptions without enclosing parentheses, so this change was deemed to break too much code.
275
276
277
+
@sjrd proposed in a [feature request](https://github.com/lampepfl/dotty-feature-requests/issues/299) that the `:` could be left out when
This is a tradeoff between conciseness and consistency. In the interest of minimality, I would leave it out of the first version of the implementation. We can always add it later if we feel a need for it.
0 commit comments