Skip to content

Commit

Permalink
Undo all changes to Tuples.
Browse files Browse the repository at this point in the history
For the two operations that we really need for NamedTuple, we
define them as "internal" helpers inside NamedTuple.

We remove or amend tests that relied on the changes to Tuple. No
tests about NamedTuple's are affected.
  • Loading branch information
sjrd committed May 6, 2024
1 parent 1e29c4f commit f96793b
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 289 deletions.
27 changes: 25 additions & 2 deletions library/src/scala/NamedTuple.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object NamedTuple:
/** The tuple consisting of all elements of this tuple followed by all elements
* of tuple `that`. The names of the two tuples must be disjoint.
*/
inline def ++ [N2 <: Tuple, V2 <: Tuple](that: NamedTuple[N2, V2])(using Tuple.Disjoint[N, N2] =:= true)
inline def ++ [N2 <: Tuple, V2 <: Tuple](that: NamedTuple[N2, V2])(using FutureTupleOps.Disjoint[N, N2] =:= true)
: NamedTuple[Tuple.Concat[N, N2], Tuple.Concat[V, V2]]
= toTuple ++ that.toTuple

Expand Down Expand Up @@ -200,6 +200,30 @@ object NamedTuple:
/** The empty named tuple */
val Empty: Empty = EmptyTuple.asInstanceOf[Empty]

@experimental
object FutureTupleOps {

/** A type level Boolean indicating whether the type `Y` contains
* none of the elements of `X`.
* @pre The elements of `X` and `Y` are assumed to be singleton types
*/
type Disjoint[X <: Tuple, Y <: Tuple] <: Boolean = X match
case x *: xs => Contains[Y, x] match
case true => false
case false => Disjoint[xs, Y]
case EmptyTuple =>
true

/** A type level Boolean indicating whether the tuple `X` has an element
* that matches `Y`.
* @pre The elements of `X` are assumed to be singleton types
*/
type Contains[X <: Tuple, Y] <: Boolean = X match
case Y *: _ => true
case _ *: xs => Contains[xs, Y]
case EmptyTuple => false
}

end NamedTuple

/** Separate from NamedTuple object so that we can match on the opaque type NamedTuple. */
Expand All @@ -214,4 +238,3 @@ object NamedTupleDecomposition:
/** The value types of a named tuple represented as a regular tuple. */
type DropNames[NT <: AnyNamedTuple] <: Tuple = NT match
case NamedTuple[_, x] => x

Loading

0 comments on commit f96793b

Please sign in to comment.