Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8851a5

Browse files
committedJul 29, 2024··
Move NamedTuple.head to NamedTupleDecomposition to ..
avoid problems encountered after inlining from scopes defining opaque types; as was already done for the other NamedTuple operations in #20504.
1 parent e3d01fa commit f8851a5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed
 

‎library/src/scala/NamedTuple.scala

+5-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object NamedTuple:
3030

3131
export NamedTupleDecomposition.{
3232
Names, DropNames,
33-
apply, size, init, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray
33+
apply, size, init, head, last, tail, take, drop, splitAt, ++, map, reverse, zip, toList, toArray, toIArray
3434
}
3535

3636
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])
@@ -43,9 +43,6 @@ object NamedTuple:
4343
// and should be reverted, just like NonEmptyList is also appealing at first, but a bad idea
4444
// in the end.
4545

46-
/** The first element value of this tuple */
47-
inline def head: Tuple.Elem[V, 0] = x.apply(0)
48-
4946
// inline def :* [L] (x: L): NamedTuple[Append[N, ???], Append[V, L] = ???
5047
// inline def *: [H] (x: H): NamedTuple[??? *: N], H *: V] = ???
5148

@@ -142,13 +139,14 @@ object NamedTupleDecomposition:
142139
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])
143140
/** The value (without the name) at index `n` of this tuple */
144141
inline def apply(n: Int): Tuple.Elem[V, n.type] =
145-
inline x.toTuple match
146-
case tup: NonEmptyTuple => tup(n).asInstanceOf[Tuple.Elem[V, n.type]]
147-
case tup => tup.productElement(n).asInstanceOf[Tuple.Elem[V, n.type]]
142+
x.toTuple.apply(n).asInstanceOf[Tuple.Elem[V, n.type]]
148143

149144
/** The number of elements in this tuple */
150145
inline def size: Tuple.Size[V] = x.toTuple.size
151146

147+
/** The first element value of this tuple */
148+
inline def head: Tuple.Elem[V, 0] = apply(0)
149+
152150
/** The last element value of this tuple */
153151
inline def last: Tuple.Last[V] = apply(size - 1).asInstanceOf[Tuple.Last[V]]
154152

0 commit comments

Comments
 (0)
Please sign in to comment.