Noel Yap
Noel Yap

Reputation: 19758

How to match case class with varargs?

I have the following Akka actor code:

class GenerateBoardActor extends Actor {
  import GenerateBoardActor._

  def receive = {
    case GenerateBoard(configuration: Seq[Configuration.PiecesConfigSpec]) => {
      sender ! Board(configuration: _*)
    }

    case generateBoard: GenerateBoard => {
      sender ! Board(generateBoard.configuration: _*)
    }
  }
}

object GenerateBoardActor {
  case class GenerateBoard(configuration: Configuration.PiecesConfigSpec*)
}

I'm thinking the two case clauses ought to be equivalent, but only the second one is ever matched. Is it possible to use the syntax of the first clause in order to match a case class with varargs? Or what is the correct syntax for the first clause?

Upvotes: 2

Views: 265

Answers (1)

chemikadze
chemikadze

Reputation: 815

Right syntax is:

case GenerateBoard(configuration @ _*) =>

Upvotes: 5

Related Questions