Skip to content

Commit bec8412

Browse files
committed
Replace convert by prefix ~ operator
1 parent ddd7449 commit bec8412

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

library/src/scala/Conversion.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ package scala
1919
* from two to one.
2020
*
2121
* The `Conversion` class can also be used to convert explicitly, using
22-
* the `convert` extension method.
22+
* the `~` operator.
2323
*/
2424
@java.lang.FunctionalInterface
2525
abstract class Conversion[-T, +U] extends Function1[T, U]:
2626
/** Convert value `x` of type `T` to type `U` */
2727
def apply(x: T): U
2828

2929
extension (x: T)
30-
/** `x.convert` converts a value `x` of type `T` to type `U` */
31-
def convert = this(x)
30+
/** `~x` converts a value `x` of type `T` to type `U` */
31+
def unary_~ = this(x)

tests/pos/convert.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ given Conversion[String, Int] = _.length
44
given Conversion[Int, String] = _.toString
55
given Conversion[Int, Date] = new Date(_)
66

7-
def f(x: String): Int = x.convert
8-
def g(x: Int): String = x.convert
9-
def h(x: Int): Date = x.convert
7+
def f(x: String): Int = ~x
8+
def g(x: Int): String = ~x
9+
def h(x: Int): Date = ~x

0 commit comments

Comments
 (0)