Skip to content

Commit 13ea06b

Browse files
committed
Make convert available without import
1 parent 758782a commit 13ea06b

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

library/src/scala/Conversion.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ package scala
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
28-
object Conversion:
2928

30-
extension [T](x: T)
31-
/** `x.convert[U]` converts a value `x` of type `T` to type `U` */
32-
def convert[U](using c: Conversion[T, U]) = c(x)
29+
extension (x: T)
30+
/** `x.convert` converts a value `x` of type `T` to type `U` */
31+
def convert = this(x)

tests/pos/convert.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import Conversion.convert
2-
31
given Conversion[String, Int] = _.length
42
given Conversion[Int, String] = _.toString
53

64
def f(x: String): Int = x.convert
7-
def g(x: Int): String = x.convert[String]
5+
def g(x: Int): String = x.convert

0 commit comments

Comments
 (0)