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
Copy file name to clipboardExpand all lines: README.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -131,6 +131,37 @@ lambda is only used in the body once, and in the same order. For more
131
131
complex type lambda expressions, you will need to use the function
132
132
syntax.
133
133
134
+
#### Inline Underscore Syntax
135
+
136
+
Since version `0.13.0` kind-projector adds an option to use underscore symbol `_` instead of `*` to define anonymous type lambdas.
137
+
The syntax roughly follows the [proposed new syntax for wildcards and placeholders](https://dotty.epfl.ch/docs/reference/changed-features/wildcards.html#migration-strategy) for Scala 3.2+ and is designed to allow cross-compilation of libraries between Scala 2 and Scala 3 while using the new Scala 3 syntax for both versions.
138
+
139
+
To enable this mode, add `-P:kind-projector:underscore-placeholders` to your scalac command-line. In sbt you may do this as follows:
This mode is designed to be used with scalac versions `2.12.14`+ and `2.13.6`+, these versions add an the ability to use `?` as the existential type wildcard ([scala/scala#9560](https://github.com/scala/scala/pull/9560)), allowing to repurpose the underscore without losing the ability to write existential types. It is not advised that you use this mode with older versions of scalac or without `-Xsource:3` flag, since you will lose the underscore syntax entirely.
146
+
147
+
Here are a few examples:
148
+
149
+
```scala
150
+
Tuple2[_, Double] // equivalent to: type R[A] = Tuple2[A, Double]
151
+
Either[Int, +_] // equivalent to: type R[+A] = Either[Int, A]
152
+
Function2[-_, Long, +_] // equivalent to: type R[-A, +B] = Function2[A, Long, B]
153
+
EitherT[_[_], Int, _] // equivalent to: type R[F[_], B] = EitherT[F, Int, B]
154
+
```
155
+
156
+
Examples with `-Xsource:3`'s `?`-wildcard:
157
+
158
+
```scala
159
+
Tuple2[_, ?] // equivalent to: type R[A] = Tuple2[A, x] forSome { type x }
160
+
Either[?, +_] // equivalent to: type R[+A] = Either[x, A] forSome { type x }
161
+
Function2[-_, ?, +_] // equivalent to: type R[-A, +B] = Function2[A, x, B] forSome { type x }
162
+
EitherT[_[_], ?, _] // equivalent to: type R[F[_], B] = EitherT[F, x, B] forSome { type x }
163
+
```
164
+
134
165
### Function Syntax
135
166
136
167
The more powerful syntax to use is the function syntax. This syntax
0 commit comments