@@ -65,7 +65,7 @@ object Tuple {
65
65
}
66
66
67
67
/** Type of the concatenation of two tuples */
68
- type Concat [X <: Tuple , + Y <: Tuple ] <: Tuple = X match {
68
+ type Concat [+ X <: Tuple , + Y <: Tuple ] <: Tuple = X match {
69
69
case Unit => Y
70
70
case x1 *: xs1 => x1 *: Concat [xs1, Y ]
71
71
}
@@ -116,6 +116,29 @@ object Tuple {
116
116
*/
117
117
type IsMappedBy [F [_]] = [X <: Tuple ] =>> X =:= Map [InverseMap [X , F ], F ]
118
118
119
+ /** Transforms a tuple `(T1, ..., Tn)` into `(T1, ..., Ti)`. */
120
+ type Take [+ T <: Tuple , N <: Int ] = N match {
121
+ case 0 => Unit
122
+ case S [n1] => T match {
123
+ case Unit => Unit
124
+ case x *: xs => Concat [x *: Unit , Take [xs, n1]]
125
+ }
126
+ }
127
+
128
+ /** Transforms a tuple `(T1, ..., Tn)` into `(Ti+1, ..., Tn)`. */
129
+ type Drop [+ T <: Tuple , N <: Int ] = N match {
130
+ case 0 => T
131
+ case S [n1] => T match {
132
+ case Unit => Unit
133
+ case x *: xs => Drop [xs, n1]
134
+ }
135
+ }
136
+
137
+ /** Splits a tuple (T1, ..., Tn) into a pair of two tuples `(T1, ..., Ti)` and
138
+ * `(Ti+1, ..., Tn)`.
139
+ */
140
+ type Split [+ T <: Tuple , N <: Int ] = (Take [T , N ], Drop [T , N ]) = (Take [T , N ], Drop [T , N ])
141
+
119
142
/** Convert an array into a tuple of unknown arity and types */
120
143
def fromArray [T ](xs : Array [T ]): Tuple = {
121
144
val xs2 = xs match {
0 commit comments