Skip to content

Commit 414de7c

Browse files
committed
Update extension docs
1 parent dd3cc4f commit 414de7c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,21 @@ Type parameters on extensions can also be combined with type parameters on the m
7878
themselves:
7979
```scala
8080
extension [T](xs: List[T])
81-
def map [U](op: T => U): List[U] = ...
81+
def def sumBy[B](f: A => B)(using Numeric[B]): B = ...
8282
```
8383

8484
Type arguments matching method type parameters are passed as usual:
8585
```scala
86-
List(1, 2, 3).map[String](_.toString)
86+
List("a", "bb", "ccc").sumBy[Int](_.length)
8787
```
8888
By contrast, type arguments matching type parameters following `extension` can be passed
8989
only if the method is referenced as a regular method:
9090
```scala
91-
map[Int](List(1, 2, 3))(_ + 1)
91+
List[String]("a", "bb", "ccc").sumBy(_.length)
92+
```
93+
or, passing, both type arguments
94+
```scala
95+
List[String]("a", "bb", "ccc").sumBy[Int](_.length)
9296
```
9397
Extensions can also take using clauses. For instance, the `+` extension above could equivalently be written with a using clause:
9498

0 commit comments

Comments
 (0)