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
As usual, type parameters of the extension method follow the defined method name. Nevertheless, such type parameters can already be used in the parameter clause that precedes
81
-
the defined method name.
74
+
As usual, type parameters of the extension method follow the defined method name. Nevertheless, such type parameters can already be used in the parameter clause that precedes the defined method name.
@@ -119,50 +112,25 @@ to pass along to the `result` method. `WrappedResult` is a fresh type, to make s
119
112
result
120
113
}
121
114
122
-
### Extension Operators
123
-
124
-
The `.` between leading parameter section and defined name in an extension method is optional. If the extension method is an operator, leaving out the dot leads to clearer
An infix operation `x op y` of an extension method `op` coming from `z` is always translated to `z.op(x)(y)`, irrespective of whether `op` is right-associative or not. So, no implicit swapping of arguments takes place for extension methods ending in a `:`. For instance,
134
-
here is the "domino"-operator brought back as an extension method:
115
+
### Rules for Overriding Extension Methods
135
116
136
-
```scala
137
-
implicitobjectSeqOps {
138
-
def [A](x: A) /: [B](xs: Seq[B])(op: (A, B) =>A):A=
139
-
xs.foldLeft(x)(op)
140
-
}
141
-
```
142
-
A call like
143
-
```scala
144
-
(0/:List(1, 2, 3)) (_ + _)
145
-
```
146
-
is translated to
147
-
```scala
148
-
SeqOps./: (0) (List(1, 2, 3)) (_ + _)
149
-
```
117
+
Extension methods may override only extension methods and can be overridden only by extension methods.
150
118
151
119
### Extension Methods and TypeClasses
152
120
153
121
The rules for expanding extension methods make sure that they work seamlessly with typeclasses. For instance, consider `SemiGroup` and `Monoid`.
The `ListOrd` class is generic - it works for any type argument `T` that is itself an instance of `Ord`. In current Scala, we could not define `ListOrd` as an implicit class since
211
-
implicit classes can only define implicit converions that take exactly one non-implicit
212
-
value parameter. We propose to drop this requirement and to also allow implicit classes
213
-
without any value parameters, or with only implicit value parameters. The generated implicit method would in each case follow the signature of the class. That is, for `ListOrd` we'd generate the method:
178
+
The `ListOrd` class is generic - it works for any type argument `T` that is itself an instance of `Ord`. In current Scala, we could not define `ListOrd` as an implicit class since implicit classes can only define implicit converions that take exactly one non-implicit value parameter. We propose to drop this requirement and to also allow implicit classes without any value parameters, or with only implicit value parameters. The generated implicit method would in each case follow the signature of the class. That is, for `ListOrd` we'd generate the method:
0 commit comments