@@ -54,30 +54,6 @@ readability and will make it much easier to understand at a glance the
54
54
most basic operation of any given method. Resist the urge to omit
55
55
parentheses simply to save two characters!
56
56
57
- ## Postfix Notation
58
-
59
- Scala allows methods that take no arguments to be invoked using postfix notation:
60
-
61
- // recommended
62
- names.toList
63
-
64
- // discourage
65
- names toList
66
-
67
- This style is unsafe, and should not be used. Since semicolons are
68
- optional, the compiler will attempt to treat it as an infix method
69
- if it can, potentially taking a term from the next line.
70
-
71
- names toList
72
- val answer = 42 // will not compile!
73
-
74
- This may result in unexpected compile errors at best, and happily
75
- compiled faulty code at worst. Although the syntax is used by some
76
- DSLs, it should be considered deprecated, and avoided.
77
-
78
- Since Scala 2.10, using postfix operator notation will result in a
79
- compiler warning.
80
-
81
57
## Infix notation
82
58
83
59
Scala has a special punctuation-free syntax for invoking methods that
@@ -116,3 +92,27 @@ Such methods are fairly rare, however, and should normally be avoided
116
92
during API design. For example, the use of the ` /: ` and ` :\ ` methods
117
93
should be avoided in preference to their better-known names,
118
94
` foldLeft ` and ` foldRight ` .
95
+
96
+ ## Postfix Notation
97
+
98
+ Scala allows methods that take no arguments to be invoked using postfix notation:
99
+
100
+ // recommended
101
+ names.toList
102
+
103
+ // discourage
104
+ names toList
105
+
106
+ This style is unsafe, and should not be used. Since semicolons are
107
+ optional, the compiler will attempt to treat it as an infix method
108
+ if it can, potentially taking a term from the next line.
109
+
110
+ names toList
111
+ val answer = 42 // will not compile!
112
+
113
+ This may result in unexpected compile errors at best, and happily
114
+ compiled faulty code at worst. Although the syntax is used by some
115
+ DSLs, it should be considered deprecated, and avoided.
116
+
117
+ Since Scala 2.10, using postfix operator notation will result in a
118
+ compiler warning.
0 commit comments