@@ -50,6 +50,9 @@ sealed trait Tuple extends Any {
50
50
*/
51
51
inline def map [F [_]](f : [t] => t => F [t]): Map [this .type , F ] =
52
52
DynamicTuple .dynamicMap(this , f)
53
+
54
+ inline def splitAt [This >: this .type <: Tuple ](n : Int ): Split [This , n.type ] =
55
+ DynamicTuple .dynamicSplitAt[This , n.type ](this , n)
53
56
}
54
57
55
58
object Tuple {
@@ -65,7 +68,7 @@ object Tuple {
65
68
}
66
69
67
70
/** Type of the concatenation of two tuples */
68
- type Concat [+ X <: Tuple , + Y <: Tuple ] <: Tuple = X match {
71
+ type Concat [X <: Tuple , + Y <: Tuple ] <: Tuple = X match {
69
72
case Unit => Y
70
73
case x1 *: xs1 => x1 *: Concat [xs1, Y ]
71
74
}
@@ -117,16 +120,16 @@ object Tuple {
117
120
type IsMappedBy [F [_]] = [X <: Tuple ] =>> X =:= Map [InverseMap [X , F ], F ]
118
121
119
122
/** Transforms a tuple `(T1, ..., Tn)` into `(T1, ..., Ti)`. */
120
- type Take [+ T <: Tuple , N <: Int ] = N match {
123
+ type Take [T <: Tuple , N <: Int ] <: Tuple = N match {
121
124
case 0 => Unit
122
125
case S [n1] => T match {
123
126
case Unit => Unit
124
- case x *: xs => Concat [ x *: Unit , Take [xs, n1] ]
127
+ case x *: xs => x *: Take [xs, n1]
125
128
}
126
129
}
127
130
128
131
/** Transforms a tuple `(T1, ..., Tn)` into `(Ti+1, ..., Tn)`. */
129
- type Drop [+ T <: Tuple , N <: Int ] = N match {
132
+ type Drop [T <: Tuple , N <: Int ] <: Tuple = N match {
130
133
case 0 => T
131
134
case S [n1] => T match {
132
135
case Unit => Unit
@@ -137,7 +140,7 @@ object Tuple {
137
140
/** Splits a tuple (T1, ..., Tn) into a pair of two tuples `(T1, ..., Ti)` and
138
141
* `(Ti+1, ..., Tn)`.
139
142
*/
140
- type Split [+ T <: Tuple , N <: Int ] = ( Take [ T , N ], Drop [ T , N ]) = (Take [T , N ], Drop [T , N ])
143
+ type Split [T <: Tuple , N <: Int ] = (Take [T , N ], Drop [T , N ])
141
144
142
145
/** Convert an array into a tuple of unknown arity and types */
143
146
def fromArray [T ](xs : Array [T ]): Tuple = {
0 commit comments