You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If such given instances are anonymous (as in the second clause), their name is synthesized from the name of the first defined extension method.
102
+
If given extensions are anonymous (as in the second clause), their name is synthesized from the name of the first defined extension method.
102
103
103
-
### Given Instances with Collective Parameters
104
+
Note: `extension` is a soft keyword, it can be used elsewhere
105
+
as a normal identifier.
104
106
105
-
If a given instance has several extension methods one can pull out the left parameter section
107
+
### Given Extensions with Collective Parameters
108
+
109
+
If a given extension defines several extension methods one can pull out the left parameter section
106
110
as well as any type parameters of these extension methods into the given instance itself.
107
111
For instance, here is a given instance with two extension methods.
108
112
```scala
109
-
givenListOps {
113
+
givenextensionlistOps: {
110
114
def (xs: List[T]) second[T]:T= xs.tail.head
111
115
def (xs: List[T]) third[T]:T= xs.tail.tail.head
112
116
}
113
117
```
114
-
The repetition in the parameters can be avoided by moving the parameters into the given instance itself. The following version is a shorthand for the code above.
118
+
The repetition in the parameters can be avoided by moving the parameters in front of the opening brace. The following version is a shorthand for the code above.
115
119
```scala
116
-
givenListOps[T](xs: List[T]) {
120
+
givenextensionlistOps: [T](xs: List[T]) {
117
121
defsecond:T= xs.tail.head
118
122
defthird:T= xs.tail.tail.head
119
123
}
@@ -170,8 +174,8 @@ As usual, type parameters of the extension method follow the defined method name
170
174
The required syntax extension just adds one clause for extension methods relative
171
175
to the [current syntax](../../internals/syntax.md).
172
176
```
173
-
DefSig ::= ...
174
-
| ‘(’ DefParam ‘)’ [nl] id [DefTypeParamClause] DefParamClauses
@@ -57,7 +57,7 @@ But the following operations would lead to type errors:
57
57
l / l2 // error: `/` is not a member fo Logarithm
58
58
```
59
59
60
-
Aside: the `any2stringadd => _` import suppression is necessary since otherwise the universal `+` operation in `Predef` would take precedence over the `+` extension method in `LogarithmOps`. We plan to resolve this wart by eliminating `any2stringadd`.
60
+
Aside: the `any2stringadd => _` import suppression is necessary since otherwise the universal `+` operation in `Predef` would take precedence over the `+` extension method in `logarithmOps`. We plan to resolve this wart by eliminating `any2stringadd`.
0 commit comments