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
7878themselves:
7979``` scala
8080extension [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
8484Type 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```
8888By contrast, type arguments matching type parameters following ` extension ` can be passed
8989only 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```
9397Extensions can also take using clauses. For instance, the ` + ` extension above could equivalently be written with a using clause:
9498
You can’t perform that action at this time.
0 commit comments