@@ -9,37 +9,44 @@ sealed trait Tuple extends Product {
9
9
import Tuple .*
10
10
11
11
/** Create a copy of this tuple as an Array */
12
- inline def toArray : Array [Object ] =
13
- runtime.Tuples .toArray(this )
12
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
13
+ private [Tuple ] inline def toArray : Array [Object ] =
14
+ Tuple .toArray(this )
14
15
15
16
/** Create a copy of this tuple as a List */
16
- inline def toList : List [ Union [ this . type ]] =
17
- this .productIterator.toList
18
- . asInstanceOf [ List [ Union [ this . type ]]]
17
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
18
+ private [ Tuple ] inline def toList : List [ Union [ this .type ]] =
19
+ Tuple .toList( this )
19
20
20
21
/** Create a copy of this tuple as an IArray */
21
- inline def toIArray : IArray [Object ] =
22
- runtime.Tuples .toIArray(this )
22
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
23
+ private [Tuple ] inline def toIArray : IArray [Object ] =
24
+ Tuple .toIArray(this )
23
25
24
26
/** Return a copy of `this` tuple with an element appended */
25
- inline def :* [This >: this .type <: Tuple , L ] (x : L ): Append [This , L ] =
26
- runtime.Tuples .append(x, this ).asInstanceOf [Append [This , L ]]
27
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
28
+ private [Tuple ] inline def :* [This >: this .type <: Tuple , L ] (x : L ): Append [This , L ] =
29
+ Tuple .:* (this )(x)
27
30
28
31
/** Return a new tuple by prepending the element to `this` tuple.
29
32
* This operation is O(this.size)
30
33
*/
34
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
31
35
inline def *: [H , This >: this .type <: Tuple ] (x : H ): H *: This =
36
+ // Tuple.*:(this)(x) // FIXME
32
37
runtime.Tuples .cons(x, this ).asInstanceOf [H *: This ]
33
38
34
39
/** Return a new tuple by concatenating `this` tuple with `that` tuple.
35
40
* This operation is O(this.size + that.size)
36
41
*/
37
- inline def ++ [This >: this .type <: Tuple ](that : Tuple ): Concat [This , that.type ] =
38
- runtime.Tuples .concat(this , that).asInstanceOf [Concat [This , that.type ]]
42
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
43
+ private [Tuple ] inline def ++ [This >: this .type <: Tuple ](that : Tuple ): Concat [This , that.type ] =
44
+ Tuple .++ (this )(that)
39
45
40
46
/** Return the size (or arity) of the tuple */
41
- inline def size [This >: this .type <: Tuple ]: Size [This ] =
42
- runtime.Tuples .size(this ).asInstanceOf [Size [This ]]
47
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
48
+ private [Tuple ] inline def size [This >: this .type <: Tuple ]: Size [This ] =
49
+ Tuple .size(this ).asInstanceOf [Size [This ]]
43
50
44
51
/** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple
45
52
* `((a1, b1), ..., (an, bn))`. If the two tuples have different sizes,
@@ -48,47 +55,136 @@ sealed trait Tuple extends Product {
48
55
* tuple types has a `EmptyTuple` tail. Otherwise the result type is
49
56
* `(A1, B1) *: ... *: (Ai, Bi) *: Tuple`
50
57
*/
51
- inline def zip [This >: this .type <: Tuple , T2 <: Tuple ](t2 : T2 ): Zip [This , T2 ] =
52
- runtime.Tuples .zip(this , t2).asInstanceOf [Zip [This , T2 ]]
58
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
59
+ private [Tuple ] inline def zip [This >: this .type <: Tuple , T2 <: Tuple ](t2 : T2 ): Zip [This , T2 ] =
60
+ Tuple .zip(this )(t2)
53
61
54
62
/** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`.
55
63
* The result is typed as `(F[A1], ..., F[An])` if the tuple type is fully known.
56
64
* If the tuple is of the form `a1 *: ... *: Tuple` (that is, the tail is not known
57
65
* to be the cons type.
58
66
*/
59
- inline def map [F [_]](f : [t] => t => F [t]): Map [this .type , F ] =
60
- runtime.Tuples .map(this , f).asInstanceOf [Map [this .type , F ]]
67
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
68
+ private [Tuple ] inline def map [F [_]](f : [t] => t => F [t]): Map [this .type , F ] =
69
+ Tuple .map(this )(f)
61
70
62
71
/** Given a tuple `(a1, ..., am)`, returns the tuple `(a1, ..., an)` consisting
63
72
* of its first n elements.
64
73
*/
65
- inline def take [This >: this .type <: Tuple ](n : Int ): Take [This , n.type ] =
66
- runtime.Tuples .take(this , n).asInstanceOf [Take [This , n.type ]]
74
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
75
+ private [Tuple ] inline def take [This >: this .type <: Tuple ](n : Int ): Take [This , n.type ] =
76
+ Tuple .take(this )(n)
67
77
68
78
69
79
/** Given a tuple `(a1, ..., am)`, returns the tuple `(an+1, ..., am)` consisting
70
80
* all its elements except the first n ones.
71
81
*/
72
- inline def drop [This >: this .type <: Tuple ](n : Int ): Drop [This , n.type ] =
73
- runtime.Tuples .drop(this , n).asInstanceOf [Drop [This , n.type ]]
82
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
83
+ private [Tuple ] inline def drop [This >: this .type <: Tuple ](n : Int ): Drop [This , n.type ] =
84
+ Tuple .drop(this )(n)
74
85
75
86
/** Given a tuple `(a1, ..., am)`, returns a pair of the tuple `(a1, ..., an)`
76
87
* consisting of the first n elements, and the tuple `(an+1, ..., am)` consisting
77
88
* of the remaining elements.
78
89
*/
79
- inline def splitAt [This >: this .type <: Tuple ](n : Int ): Split [This , n.type ] =
80
- runtime.Tuples .splitAt(this , n).asInstanceOf [Split [This , n.type ]]
90
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
91
+ private [Tuple ] inline def splitAt [This >: this .type <: Tuple ](n : Int ): Split [This , n.type ] =
92
+ Tuple .splitAt(this )(n)
81
93
82
94
/** Given a tuple `(a1, ..., am)`, returns the reversed tuple `(am, ..., a1)`
83
95
* consisting all its elements.
84
96
*/
85
- @ experimental
86
- inline def reverse [This >: this .type <: Tuple ]: Reverse [This ] =
87
- runtime.Tuples .reverse(this ).asInstanceOf [Reverse [This ]]
97
+ @ experimental // We may remove this one May not need to add this method if it is not yet stable
98
+ // @publicInBinary // For TASTy compatibility, but not actually available in the the binary
99
+ private [Tuple ] inline def reverse [This >: this .type <: Tuple ]: Reverse [This ] =
100
+ Tuple .reverse(this )
88
101
}
89
102
90
103
object Tuple {
91
104
105
+ // FIXME
106
+ // fails tests/run-deep-subtype/Tuple-size.scala:40:19
107
+ // 40 | assert(1 == (1 *: Tuple()).size)
108
+ // | ^^
109
+ // | illegal repeated type application
110
+ // | You might have meant something like:
111
+ // | Tuple.*:[Int, EmptyTuple.type]
112
+ // extension [H](x: H)
113
+ // /** Return a new tuple by prepending the element to `tail` tuple.
114
+ // * This operation is O(tail.size)
115
+ // */
116
+ // def *:[T <: Tuple](tail: T): H *: T = runtime.Tuples.cons(x, tail).asInstanceOf[H *: T]
117
+
118
+ extension [This <: Tuple ](tuple : This )
119
+
120
+ /** Return the size (or arity) of the tuple */
121
+ def size : Size [This ] = runtime.Tuples .size(tuple).asInstanceOf [Size [This ]]
122
+
123
+ /** Return a copy of `tuple` with an element appended */
124
+ def :* [X ] (x : X ): Append [This , X ] = runtime.Tuples .append(x, tuple).asInstanceOf [Append [This , X ]]
125
+
126
+ /** Return a new tuple by concatenating `this` tuple with `that` tuple.
127
+ * This operation is O(this.size + that.size)
128
+ */
129
+ def ++ (that : Tuple ): Concat [This , that.type ] = // TODO change signature? def ++[That <: Tuple](that: That): Concat[This, That]
130
+ runtime.Tuples .concat(tuple, that).asInstanceOf [Concat [This , that.type ]]
131
+
132
+ /** Given a tuple `(a1, ..., am)`, returns the reversed tuple `(am, ..., a1)`
133
+ * consisting all its elements.
134
+ */
135
+ @ experimental
136
+ def reverse : Reverse [This ] =
137
+ runtime.Tuples .reverse(tuple).asInstanceOf [Reverse [This ]]
138
+
139
+ /** Given two tuples, `(a1, ..., an)` and `(a1, ..., an)`, returns a tuple
140
+ * `((a1, b1), ..., (an, bn))`. If the two tuples have different sizes,
141
+ * the extra elements of the larger tuple will be disregarded.
142
+ * The result is typed as `((A1, B1), ..., (An, Bn))` if at least one of the
143
+ * tuple types has a `EmptyTuple` tail. Otherwise the result type is
144
+ * `(A1, B1) *: ... *: (Ai, Bi) *: Tuple`
145
+ */
146
+ def zip [That <: Tuple ](that : That ): Zip [This , That ] = // TODO change signature? def zip(that: Tuple): Zip[This, that.type]
147
+ runtime.Tuples .zip(tuple, that).asInstanceOf [Zip [This , That ]]
148
+
149
+ /** Called on a tuple `(a1, ..., an)`, returns a new tuple `(f(a1), ..., f(an))`.
150
+ * The result is typed as `(F[A1], ..., F[An])` if the tuple type is fully known.
151
+ * If the tuple is of the form `a1 *: ... *: Tuple` (that is, the tail is not known
152
+ * to be the cons type.
153
+ */
154
+ def map [F [_]](f : [t] => t => F [t]): Map [This , F ] =
155
+ runtime.Tuples .map(tuple, f).asInstanceOf [Map [This , F ]]
156
+
157
+ /** Given a tuple `(a1, ..., am)`, returns the tuple `(a1, ..., an)` consisting
158
+ * of its first n elements.
159
+ */
160
+ def take (n : Int ): Take [This , n.type ] =
161
+ runtime.Tuples .take(tuple, n).asInstanceOf [Take [This , n.type ]]
162
+
163
+
164
+ /** Given a tuple `(a1, ..., am)`, returns the tuple `(an+1, ..., am)` consisting
165
+ * all its elements except the first n ones.
166
+ */
167
+ def drop (n : Int ): Drop [This , n.type ] =
168
+ runtime.Tuples .drop(tuple, n).asInstanceOf [Drop [This , n.type ]]
169
+
170
+ /** Given a tuple `(a1, ..., am)`, returns a pair of the tuple `(a1, ..., an)`
171
+ * consisting of the first n elements, and the tuple `(an+1, ..., am)` consisting
172
+ * of the remaining elements.
173
+ */
174
+ def splitAt (n : Int ): Split [This , n.type ] =
175
+ runtime.Tuples .splitAt(tuple, n).asInstanceOf [Split [This , n.type ]]
176
+
177
+ /** Create a copy of this tuple as a List */
178
+ def toList : List [Union [This ]] =
179
+ tuple.productIterator.toList.asInstanceOf [List [Union [This ]]]
180
+
181
+ extension (tuple : Tuple )
182
+ /** Create a copy of this tuple as an Array */
183
+ def toArray : Array [Object ] = runtime.Tuples .toArray(tuple)
184
+
185
+ /** Create a copy of this tuple as an IArray */
186
+ def toIArray : IArray [Object ] = runtime.Tuples .toIArray(tuple)
187
+
92
188
/** Type of a tuple with an element appended */
93
189
type Append [X <: Tuple , Y ] <: NonEmptyTuple = X match {
94
190
case EmptyTuple => Y *: EmptyTuple
0 commit comments