How to pattern match large Scala case classes?

前端 未结 4 2034
攒了一身酷
攒了一身酷 2020-12-05 01:43

Consider the following Scala case class:

case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)

Pattern matching allows me

4条回答
  •  时光取名叫无心
    2020-12-05 02:41

    You can create a new case class which is a summary of your larger case class

    case class WideLoad(a: String, b: Int, c: Float, d: ActorRef, e: Date)
    case class WideLoadSummary(d: ActorRef, e: Date)
    

    And then pattern match as normal.

    val someVal = WideLoadSummary(wideload.d, wideload.e)
    
    someVal match {
        case WideLoadSummary(d, _) => d ! SomeMessage(...)
    }
    

提交回复
热议问题