Skip to content

Commit bc8a132

Browse files
committed
Fix a code example that was not consistent with its description
1 parent 9e3da24 commit bc8a132

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

docs/docs/reference/contextual/extension-methods.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,30 +65,30 @@ the two swaps cancel each other out).
6565

6666
### Generic Extensions
6767

68-
It is also possible to extend generic types by adding type parameters to an extension. For instance:
68+
It is also possible to extend generic types by adding type parameters to an extension. For instance:
6969

70-
```scala
71-
extension [T](xs: List[T])
72-
def second = xs.tail.head
70+
```scala
71+
extension [T](xs: List[T])
72+
def second = xs.tail.head
7373

74-
extension [T: Numeric](x: T)
75-
def + (y: T): T = summon[Numeric[T]].plus(x, y)
74+
extension [T: Numeric](x: T)
75+
def + (y: T): T = summon[Numeric[T]].plus(x, y)
7676
```
7777

7878
If an extension method has type parameters, they come immediately after `extension` and are followed by the extended parameter.
7979
When calling a generic extension method, any explicitly given type arguments follow the method name. So the `second` method could be instantiated as follows.
8080

8181
```scala
82-
List(1, 2, 3).second[Int]
82+
List(1, 2, 3).second[Int]
8383
```
8484

8585
Of course, the type argument here would usually be left out since it can be inferred.
8686

8787
Extensions can also take using clauses. For instance, the `+` extension above could equivalently be written with a using clause:
8888

8989
```scala
90-
extension [T](x: T)(using n: Numeric[T])
91-
def - (y: T): T = n.minus(x, y)
90+
extension [T](x: T)(using n: Numeric[T])
91+
def + (y: T): T = n.plus(x, y)
9292
```
9393

9494
**Note**: Type parameters have to be given after the `extension` keyword;

0 commit comments

Comments
 (0)