File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
docs/docs/reference/contextual Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -78,17 +78,21 @@ Type parameters on extensions can also be combined with type parameters on the m
78
78
themselves:
79
79
``` scala
80
80
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 = ...
82
82
```
83
83
84
84
Type arguments matching method type parameters are passed as usual:
85
85
``` scala
86
- List (1 , 2 , 3 ).map[ String ](_.toString )
86
+ List (" a " , " bb " , " ccc " ).sumBy[ Int ](_.length )
87
87
```
88
88
By contrast, type arguments matching type parameters following ` extension ` can be passed
89
89
only if the method is referenced as a regular method:
90
90
``` 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)
92
96
```
93
97
Extensions can also take using clauses. For instance, the ` + ` extension above could equivalently be written with a using clause:
94
98
You can’t perform that action at this time.
0 commit comments