Skip to content

Commit 156a500

Browse files
committed
Use X <: Tuple bound for Tuple.{Init|Last}
1 parent 809d7b7 commit 156a500

File tree

1 file changed

+8
-22
lines changed

1 file changed

+8
-22
lines changed

library/src/scala/Tuple.scala

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,37 +84,23 @@ object Tuple {
8484
}
8585

8686
/** Type of the initial part of the tuple without its last element */
87-
type Init[X <: NonEmptyTuple] <: Tuple = X match {
87+
@experimental
88+
type Init[X <: Tuple] <: Tuple = X match {
8889
case _ *: EmptyTuple => EmptyTuple
8990
case x *: xs =>
90-
xs match {
91-
case _ *: EmptyTuple =>
92-
x *: EmptyTuple
93-
case _ =>
94-
x *: Init[xs]
95-
}
91+
x *: Init[xs]
9692
}
9793

9894
/** Type of the tail of a tuple */
9995
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
10096
case _ *: xs => xs
10197
}
10298

103-
/** Type of the last of a tuple */
104-
type Last[X <: NonEmptyTuple] = Reduce[X, EmptyTuple] match {
105-
case x *: xs => xs match {
106-
case EmptyTuple => x
107-
}
108-
}
109-
110-
/** Type of the reduce of the first tuple to a tuple of arity 1 or provide the second tuple as a result */
111-
type Reduce[X <: Tuple, Y <: Tuple] <: Tuple = X match {
112-
case EmptyTuple => Y
113-
case x *: xs => xs match {
114-
case EmptyTuple => x *: EmptyTuple
115-
case y *: ys =>
116-
Reduce[ys, y *: EmptyTuple]
117-
}
99+
/** Type of the last element of a tuple */
100+
@experimental
101+
type Last[X <: Tuple] = X match {
102+
case x *: EmptyTuple => x
103+
case _ *: xs => Last[xs]
118104
}
119105

120106
/** Type of the concatenation of two tuples */

0 commit comments

Comments
 (0)