|
1 | | -trait Con[-T] extends (T => Unit): |
| 1 | +trait ConTU[-T] extends (T => Unit): |
2 | 2 | def apply(t: T): Unit |
3 | 3 |
|
4 | | -trait Con2[-T] extends (T => Int): |
| 4 | +trait ConTI[-T] extends (T => Int): |
5 | 5 | def apply(t: T): Int |
6 | 6 |
|
7 | | -trait Con3[+R] extends (() => R): |
| 7 | +trait ConTS[-T] extends (T => String): |
| 8 | + def apply(t: T): String |
| 9 | + |
| 10 | +trait ConIR[+R] extends (Int => R): |
| 11 | + def apply(t: Int): R |
| 12 | + |
| 13 | +trait ConSR[+R] extends (String => R): |
| 14 | + def apply(t: String): R |
| 15 | + |
| 16 | +trait ConUR[+R] extends (() => R): |
8 | 17 | def apply(): R |
9 | 18 |
|
| 19 | +trait ConII extends (Int => Int): |
| 20 | + def apply(t: Int): Int |
| 21 | + |
| 22 | +trait ConSI extends (String => Int): |
| 23 | + def apply(t: String): Int |
| 24 | + |
| 25 | +trait ConIS extends (Int => String): |
| 26 | + def apply(t: Int): String |
| 27 | + |
| 28 | +trait ConUU extends (() => Unit): |
| 29 | + def apply(): Unit |
| 30 | + |
10 | 31 | trait F1[-T, +R]: |
11 | 32 | def apply(t: T): R |
12 | 33 |
|
13 | | -trait SF[-T] extends F1[T, Unit]: |
| 34 | +trait SFTU[-T] extends F1[T, Unit]: |
14 | 35 | def apply(t: T): Unit |
15 | 36 |
|
16 | | -trait F1U[-T]: |
17 | | - def apply(t: T): Unit |
| 37 | +trait SFTI[-T] extends F1[T, Int]: |
| 38 | + def apply(t: T): Int |
| 39 | + |
| 40 | +trait SFTS[-T] extends F1[T, String]: |
| 41 | + def apply(t: T): String |
| 42 | + |
| 43 | +trait SFIR [+R] extends F1[Int, R]: |
| 44 | + def apply(t: Int): R |
| 45 | + |
| 46 | +trait SFSR [+R] extends F1[String, R]: |
| 47 | + def apply(t: String): R |
| 48 | + |
| 49 | +trait SFII extends F1[Int, Int]: |
| 50 | + def apply(t: Int): Int |
| 51 | + |
| 52 | +trait SFSI extends F1[String, Int]: |
| 53 | + def apply(t: String): Int |
| 54 | + |
| 55 | +trait SFIS extends F1[Int, String]: |
| 56 | + def apply(t: Int): String |
| 57 | + |
| 58 | +trait SFIU extends F1[Int, Unit]: |
| 59 | + def apply(t: Int): Unit |
18 | 60 |
|
19 | | -trait SF2 extends F1U[String]: |
20 | | - def apply(t: String): Unit |
21 | 61 |
|
22 | 62 | object Test: |
23 | 63 | def main(args: Array[String]): Unit = |
24 | | - val f1: (Int => Unit) = i => println(i) |
25 | | - f1(1) |
| 64 | + val fIU: (Int => Unit) = (x: Int) => println(x) |
| 65 | + fIU(1) |
| 66 | + |
| 67 | + val fIS: (Int => String) = (x: Int) => x.toString |
| 68 | + println(fIS(2)) |
| 69 | + |
| 70 | + val fUI: (() => Int) = () => 3 |
| 71 | + println(fUI()) |
| 72 | + |
| 73 | + val conITU: ConTU[Int] = (x: Int) => println(x) |
| 74 | + conITU(11) |
| 75 | + val conITI: ConTI[Int] = (x: Int) => x |
| 76 | + println(conITI(12)) |
| 77 | + val conITS: ConTS[Int] = (x: Int) => x.toString |
| 78 | + println(conITS(13)) |
| 79 | + val conSTS: ConTS[String] = (x: String) => x |
| 80 | + println(conSTS("14")) |
| 81 | + |
| 82 | + val conIRS: ConIR[String] = (x: Int) => x.toString |
| 83 | + println(conIRS(15)) |
| 84 | + val conIRI: ConIR[Int] = (x: Int) => x |
| 85 | + println(conIRI(16)) |
| 86 | + val conIRU: ConIR[Unit] = (x: Int) => println(x) |
| 87 | + conIRU(17) |
| 88 | + |
| 89 | + val conSRI: ConSR[Int] = (x: String) => x.toInt |
| 90 | + println(conSRI("18")) |
| 91 | + val conURI: ConUR[Int] = () => 19 |
| 92 | + println(conURI()) |
| 93 | + val conURU: ConUR[Unit] = () => println("20") |
| 94 | + conURU() |
| 95 | + |
| 96 | + val conII: ConII = (x: Int) => x |
| 97 | + println(conII(21)) |
| 98 | + val conSI: ConSI = (x: String) => x.toInt |
| 99 | + println(conSI("22")) |
| 100 | + val conIS: ConIS = (x: Int) => x.toString |
| 101 | + println(conIS(23)) |
| 102 | + val conUU: ConUU = () => println("24") |
| 103 | + conUU() |
| 104 | + |
| 105 | + val ffIU: F1[Int, Unit] = (x: Int) => println(x) |
| 106 | + ffIU(31) |
| 107 | + val ffIS: F1[Int, String] = (x: Int) => x.toString |
| 108 | + println(ffIS(32)) |
| 109 | + |
| 110 | + val sfITU: SFTU[Int] = (x: Int) => println(x) |
| 111 | + sfITU(41) |
| 112 | + val sfSTU: SFTU[String] = (x: String) => println(x) |
| 113 | + sfSTU("42") |
26 | 114 |
|
27 | | - val c1: Con[Int] = i => println(i) |
28 | | - c1(2) |
| 115 | + val sfITI: SFTI[Int] = (x: Int) => x |
| 116 | + println(sfITI(43)) |
| 117 | + val sfSTI: SFTI[String] = (x: String) => x.toInt |
| 118 | + println(sfSTI("44")) |
29 | 119 |
|
30 | | - val c2: Con2[Int] = i => { println(i); i } |
31 | | - c2(3) |
| 120 | + val sfITS: SFTS[Int] = (x: Int) => x.toString |
| 121 | + println(sfITS(45)) |
| 122 | + val sfSTS: SFTS[String] = (x: String) => x |
| 123 | + println(sfSTS("46")) |
32 | 124 |
|
33 | | - val c3: Con3[Int] = () => 42 |
34 | | - println(c3()) |
| 125 | + val sfIRI: SFIR[Int] = (x: Int) => x |
| 126 | + println(sfIRI(51)) |
| 127 | + val sfIRS: SFIR[String] = (x: Int) => x.toString |
| 128 | + println(sfIRS(52)) |
| 129 | + val sfIRU: SFIR[Unit] = (x: Int) => println(x) |
| 130 | + sfIRU(53) |
35 | 131 |
|
36 | | - val c4: Con3[Unit] = () => println("hello") |
37 | | - c4() |
| 132 | + val sfSRI: SFSR[Int] = (x: String) => x.toInt |
| 133 | + println(sfSRI("55")) |
| 134 | + val sfSRS: SFSR[String] = (x: String) => x |
| 135 | + println(sfSRS("56")) |
| 136 | + val sfSRU: SFSR[Unit] = (x: String) => println(x) |
| 137 | + sfSRU("57") |
38 | 138 |
|
39 | | - val f5: SF[String] = s => println(s) |
40 | | - f5("world") |
| 139 | + val sfII: SFII = (x: Int) => x |
| 140 | + println(sfII(61)) |
| 141 | + val sfSI: SFSI = (x: String) => x.toInt |
| 142 | + println(sfSI("62")) |
| 143 | + val sfIS: SFIS = (x: Int) => x.toString |
| 144 | + println(sfIS(63)) |
| 145 | + val sfIU: SFIU = (x: Int) => println(x) |
| 146 | + sfIU(64) |
41 | 147 |
|
42 | | - val f6: SF2 = i => println(i) |
43 | | - f6("!!") |
|
0 commit comments