Skip to content

Commit

Permalink
Move NamedTuple.head to NamedTupleDecomposition to ..
Browse files Browse the repository at this point in the history
avoid problems encountered after inlining from scopes defining opaque types;
as was already done for the other NamedTuple operations in scala#20504.
  • Loading branch information
EugeneFlesselle committed Jul 29, 2024
1 parent e3d01fa commit f8851a5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ object NamedTuple:

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

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

/** The first element value of this tuple */
inline def head: Tuple.Elem[V, 0] = x.apply(0)

// inline def :* [L] (x: L): NamedTuple[Append[N, ???], Append[V, L] = ???
// inline def *: [H] (x: H): NamedTuple[??? *: N], H *: V] = ???

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

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

/** The first element value of this tuple */
inline def head: Tuple.Elem[V, 0] = apply(0)

/** The last element value of this tuple */
inline def last: Tuple.Last[V] = apply(size - 1).asInstanceOf[Tuple.Last[V]]

Expand Down

0 comments on commit f8851a5

Please sign in to comment.