我有以下案例类
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")
答案 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"