-1

I have the following case class

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

so, I can do the following

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

and I would like to able to call parts of the LeftHandSide by name too, e.g:

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

And then:

MyClass((Set("yu", "ye"), "bee"), 0.03).filter(x => x.LeftHandSide.Part2 != "bee")
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
  • What is your question? – Yuval Itzchakov Aug 15 '16 at 09:50
  • I cannot create such a class: case class MyClass (LeftHandSide: (Part1: Set[String], Part2: String), RightHandSide: Double) – Simon Pastuch Aug 15 '16 at 09:54
  • Is this line compiling in your program? Its giving an error in the repl. filter method is only applicable on collections. MyClass((Set("yu", "ye"), "bee"), 0.03).filter( x=> x.RightHandSide>4) – Samar Aug 15 '16 at 10:06

1 Answers1

2

Create an additional case class called LeftHandSide:

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

And use that in MyClass:

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

And then:

val myClass = MyClass(LeftHandSide(Set("yu", "ye"), "bee"), 0.03)
myClass.leftHandSide.partTwo != "bee"
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321