Skip to content

Commit

Permalink
Move NamedTuple.head to NamedTupleDecomposition (#21308)
Browse files Browse the repository at this point in the history
This is in particular necessary for #21291,
to avoid problems encountered after inlining from scopes defining opaque
types (such as in the example below),
as was already done for the other NamedTuple operations in #20504.
  • Loading branch information
bishabosha authored Jul 31, 2024
2 parents 927eb5b + 32e4056 commit 5da1855
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 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 @@ -149,6 +146,9 @@ object NamedTupleDecomposition:
/** 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 5da1855

Please sign in to comment.