scala中的内部案例类

时间:2016-08-15 09:46:58

标签: scala case-class

我有以下案例类

case class MyClass (LeftHandSide: (Set[String], String), RightHandSide: Double)

所以,我可以做以下

MyClass((Set("yu", "ye"), "bee"), 0.03).filter( x=> x.RightHandSide>4)

我希望能够通过名称调用LeftHandSide的部分内容,例如:

case class MyClass (LeftHandSide: (Part1: Set[String], Part2: String), RightHandSide: Double)

然后:

MyClass((Set("yu", "ye"), "bee"), 0.03).filter(x => x.LeftHandSide.Part2 != "bee")

1 个答案:

答案 0 :(得分:2)

创建一个名为LeftHandSide的其他案例类:

case class LeftHandSide(partOne: Set[String], partTwo: String)

并在MyClass中使用它:

case class MyClass(leftHandSide: LeftHandSide, rightHandSide: Double)

然后:

val myClass = MyClass(LeftHandSide(Set("yu", "ye"), "bee"), 0.03)
myClass.leftHandSide.partTwo != "bee"