Skip to content

Commit d1fecbb

Browse files
committed
avoid postfix syntax in operator tour
since it's no longer a recommended part of the language
1 parent 8b1bc02 commit d1fecbb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: tutorials/tour/operators.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,28 @@ tutorial-next: automatic-closures
1010
tutorial-previous: local-type-inference
1111
---
1212

13-
Any method which takes a single parameter can be used as an *infix operator* in Scala. Here is the definition of class `MyBool` which defines three methods `and`, `or`, and `negate`.
13+
Any method which takes a single parameter can be used as an *infix operator* in Scala. Here is the definition of class `MyBool` which includes methods `and` and `or`:
1414

1515
```tut
16-
class MyBool(x: Boolean) {
16+
case class MyBool(x: Boolean) {
1717
def and(that: MyBool): MyBool = if (x) that else this
1818
def or(that: MyBool): MyBool = if (x) this else that
19-
def negate: MyBool = new MyBool(!x)
19+
def negate: MyBool = MyBool(!x)
2020
}
2121
```
2222

2323
It is now possible to use `and` and `or` as infix operators:
2424

2525
```tut
26-
def not(x: MyBool) = x negate; // semicolon required here
26+
def not(x: MyBool) = x.negate
2727
def xor(x: MyBool, y: MyBool) = (x or y) and not(x and y)
2828
```
2929

30-
As the first line of this code shows, it is also possible to use nullary methods as postfix operators. The second line defines an `xor` function using the `and` and `or` methods as well as the new `not` function. In this example the use of _infix operators_ helps to make the definition of `xor` more readable.
30+
This helps to make the definition of `xor` more readable.
3131

3232
Here is the corresponding code in a more traditional object-oriented programming language syntax:
3333

3434
```tut
35-
def not(x: MyBool) = x.negate; // semicolon required here
35+
def not(x: MyBool) = x.negate
3636
def xor(x: MyBool, y: MyBool) = x.or(y).and(x.and(y).negate)
3737
```

0 commit comments

Comments
 (0)