File tree 1 file changed +46
-0
lines changed 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import scala .concurrent .Future
2
+ object magnets {
3
+
4
+ enum StatusCode {
5
+ case OK , Error
6
+ }
7
+
8
+ trait Marshaller [T ] { def marshall (t : T ): String }
9
+ class HttpResponse
10
+
11
+ sealed trait CompletionMagnet {
12
+ type Result
13
+ def apply (): Result
14
+ }
15
+
16
+ object CompletionMagnet {
17
+
18
+ extend (StatusCode , type T : Marshaller ) implements CompletionMagnet {
19
+ type Result = String
20
+ def apply (): String = implicitly[Marshaller [T ]].marshall(this ._2)
21
+ }
22
+
23
+ extend Future [HttpResponse ] implements CompletionMagnet {
24
+ type Result = Int
25
+ def apply (): Int = 1
26
+ }
27
+
28
+ extend Future [StatusCode ] implements CompletionMagnet {
29
+ type Result = Int
30
+ def apply (): Int = 2
31
+ }
32
+ }
33
+
34
+ implicit object stringMarshaller extends Marshaller [String ] {
35
+ def marshall (x : String ): String = x
36
+ }
37
+
38
+ def complete (magnet : CompletionMagnet ): magnet.Result = magnet()
39
+ }
40
+
41
+ object Test extends App {
42
+ import magnets ._
43
+
44
+ assert(complete((StatusCode .OK , " hello" )) == " hello" )
45
+
46
+ }
You can’t perform that action at this time.
0 commit comments