File tree 1 file changed +42
-0
lines changed
1 file changed +42
-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
+ trait X {
25
+ type T
26
+ def t : T
27
+ }
28
+ val x : X = ???
29
+
30
+ {
31
+ given ConversionFunction [(x : X ) => x.T ] = ConversionFunction ((x : X ) => x.t)
32
+ // val a: x.T = x
33
+ val a : x.T = ConversionFunction .get[(x : X ) => x.T ].apply(x)
34
+ }
35
+
36
+ {
37
+ given ConversionFunction [(x : X ) => x.T ] = ConversionFunction (_.t)
38
+ // val a: x.T = x
39
+ val a : x.T = ConversionFunction .get[(x : X ) => x.T ].apply(x)
40
+ }
41
+
42
+ }
You can’t perform that action at this time.
0 commit comments