解压缩Scala中的元组类型

jpa*_*cek 7 types scala tuples

我只是想知道,我可以将元组类型分解为Scala中的组件类型吗?

我的意思是,这样的事情

trait Container {
  type Element
}

trait AssociativeContainer extends Container {
  type Element <: (Unit, Unit)
  def get(x : Element#First) : Element#Second
}
Run Code Online (Sandbox Code Playgroud)

Jor*_*tiz 3

您本身无法解压,但也许这可以实现您想要的:

  type First
  type Second
  type Element = (First, Second)
  def get(x: First): Second
Run Code Online (Sandbox Code Playgroud)