File tree 1 file changed +56
-0
lines changed
1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ package scala
2
+
3
+
4
+ object ConversionFunction {
5
+
6
+ opaque type ConversionFunction [+ F <: Nothing => Any ] = F
7
+
8
+ def apply [F <: Nothing => Any ](f : F ): ConversionFunction [F ] = f
9
+ def get [F <: Nothing => Any ](using f : ConversionFunction [F ]): F = f
10
+
11
+ }
12
+
13
+ type ConversionFunction [+ F <: Nothing => Any ] =
14
+ ConversionFunction .ConversionFunction [F ]
15
+
16
+ object Test {
17
+
18
+ {
19
+ given ConversionFunction [Int => String ] = ConversionFunction (_.toString)
20
+ // val a: String = 3
21
+ val a : String = ConversionFunction .get[3 => String ].apply(3 )
22
+ }
23
+
24
+ {
25
+ given ConversionFunction [(x : Int ) => x.type ] = ConversionFunction ((x : Int ) => x)
26
+ // val a: String = 3
27
+ val a : Int = ConversionFunction .get[3 => Int ].apply(3 )
28
+ }
29
+
30
+
31
+ {
32
+ trait X {
33
+ type T
34
+ def t : T
35
+ }
36
+ val x : X = ???
37
+
38
+ given ConversionFunction [(x : X ) => x.T ] = ConversionFunction ((x : X ) => x.t)
39
+ // val a: String = 3
40
+ val a : x.T = ConversionFunction .get[(x : X ) => x.T ].apply(x)
41
+ }
42
+
43
+
44
+ {
45
+ trait X {
46
+ type T
47
+ def t : T
48
+ }
49
+ val x : X = ???
50
+
51
+ given ConversionFunction [(x : X ) => x.T ] = ConversionFunction (_.t)
52
+ // val a: String = 3
53
+ val a : x.T = ConversionFunction .get[(x : X ) => x.T ].apply(x)
54
+ }
55
+
56
+ }
You can’t perform that action at this time.
0 commit comments