Skip to content

Commit

Permalink
Drop asInstanceOf from the NamedTuple term ops where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneFlesselle committed Oct 4, 2024
1 parent f931a6d commit 12eb487
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions library/src-bootstrapped/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ object NamedTupleDecomposition:
inline def head: Head[NamedTuple[N, V]] = apply(0)

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

/** The tuple consisting of all elements of this tuple except the last one */
inline def init: Init[NamedTuple[N, V]] =
x.toTuple.take(size - 1).asInstanceOf[Init[NamedTuple[N, V]]]
x.take(size - 1).asInstanceOf[Init[NamedTuple[N, V]]]

/** The tuple consisting of all elements of this tuple except the first one */
inline def tail: Tail[NamedTuple[N, V]] =
x.toTuple.drop(1).asInstanceOf[Tail[NamedTuple[N, V]]]
inline def tail: Tail[NamedTuple[N, V]] = x.toTuple.drop(1)

/** The tuple consisting of the first `n` elements of this tuple, or all
* elements if `n` exceeds `size`.
Expand All @@ -182,7 +181,7 @@ object NamedTupleDecomposition:
* If `x = (n1 = v1, ..., ni = vi)` then `x.map(f) = `(n1 = f(v1), ..., ni = f(vi))`.
*/
inline def map[F[_]](f: [t] => t => F[t]): Map[NamedTuple[N, V], F] =
x.toTuple.map(f).asInstanceOf[NamedTuple[N, Tuple.Map[V, F]]]
x.toTuple.map(f)

/** The named tuple consisting of all elements of this tuple in reverse */
inline def reverse: Reverse[NamedTuple[N, V]] = x.toTuple.reverse
Expand All @@ -198,7 +197,7 @@ object NamedTupleDecomposition:
x.toTuple.zip(that.toTuple)

/** A list consisting of all element values */
inline def toList: List[Tuple.Union[V]] = x.toTuple.toList.asInstanceOf[List[Tuple.Union[V]]]
inline def toList: List[Tuple.Union[V]] = x.toTuple.toList

/** An array consisting of all element values */
inline def toArray: Array[Object] = x.toTuple.toArray
Expand Down

0 comments on commit 12eb487

Please sign in to comment.