Skip to content

Commit b3b3fb0

Browse files
committed
Add documentation
1 parent d2bc81f commit b3b3fb0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

library/src-3.x/scala/Tuple.scala

+24
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,51 @@ import internal._
55

66
import scala.runtime.DynamicTuple
77

8+
/** Tuple of arbitrary arity */
89
sealed trait Tuple extends Any {
910
import Tuple._
1011

12+
/** Create a copy this tuple as an Array */
1113
inline def toArray: Array[Object] =
1214
DynamicTuple.dynamicToArray(this)
1315

16+
/** Return a new tuple by prepending the element to `this` tuple.
17+
* This opteration is O(this.size)
18+
*/
1419
inline def *: [H, This >: this.type <: Tuple] (x: H): H *: This =
1520
DynamicTuple.dynamicCons[This, H](this, x)
1621

22+
/** Return a new tuple by concatenating `this` tuple with `that` tuple.
23+
* This opteration is O(this.size + that.size)
24+
*/
1725
inline def ++ [This >: this.type <: Tuple](that: Tuple): Concat[This, that.type] =
1826
DynamicTuple.dynamicConcat[This, that.type](this, that)
1927

28+
/** Return the size (or arity) of the tuple */
2029
inline def size[This >: this.type <: Tuple]: Size[This] =
2130
DynamicTuple.dynamicSize(this)
2231

2332
}
2433

2534
object Tuple {
2635

36+
/** Type of the head of a tuple */
2737
type Head[X <: NonEmptyTuple] = X match {
2838
case x *: _ => x
2939
}
3040

41+
/** Type of the tail of a tuple */
3142
type Tail[X <: NonEmptyTuple] <: Tuple = X match {
3243
case _ *: xs => xs
3344
}
3445

46+
/** Type of the concatenation of two tuples */
3547
type Concat[X <: Tuple, +Y <: Tuple] <: Tuple = X match {
3648
case Unit => Y
3749
case x1 *: xs1 => x1 *: Concat[xs1, Y]
3850
}
3951

52+
/** Type of the element a position N in the tuple X */
4053
type Elem[X <: Tuple, N] = X match {
4154
case x *: xs =>
4255
N match {
@@ -45,11 +58,13 @@ object Tuple {
4558
}
4659
}
4760

61+
/** Literal constant Int size of a tuple */
4862
type Size[X] <: Int = X match {
4963
case Unit => 0
5064
case x *: xs => S[Size[xs]]
5165
}
5266

67+
/** Convert an array into a tuple of unknown arity and types */
5368
def fromArray[T](xs: Array[T]): Tuple = {
5469
val xs2 = xs match {
5570
case xs: Array[Object] => xs
@@ -58,20 +73,29 @@ object Tuple {
5873
DynamicTuple.dynamicFromArray[Tuple](xs2)
5974
}
6075

76+
/** Convert a Product into a tuple of unknown arity and types */
6177
def fromProduct(product: Product): Tuple =
6278
runtime.DynamicTuple.dynamicFromProduct[Tuple](product)
6379

6480
}
6581

82+
/** Tuple of arbitrary non-zero arity */
6683
sealed trait NonEmptyTuple extends Tuple {
6784
import Tuple._
6885

86+
/** Get the i-th element of this tuple.
87+
* Equivalent to productElement but with a precise return type.
88+
*/
6989
inline def apply[This >: this.type <: NonEmptyTuple](n: Int): Elem[This, n.type] =
7090
DynamicTuple.dynamicApply[This, n.type](this, n)
7191

92+
/** Get the head of this tuple */
7293
inline def head[This >: this.type <: NonEmptyTuple]: Head[This] =
7394
DynamicTuple.dynamicApply[This, 0](this, 0)
7495

96+
/** Get the tail of this tuple.
97+
* This opteration is O(this.size)
98+
*/
7599
inline def tail[This >: this.type <: NonEmptyTuple]: Tail[This] =
76100
DynamicTuple.dynamicTail[This](this)
77101

0 commit comments

Comments
 (0)