using variable length argument in scala

前端 未结 1 837
半阙折子戏
半阙折子戏 2020-12-01 17:03

I know how to define a method with variable length argument:

  case class taxonomy(vocabularies:(String,Set[String])*)

and client code is

相关标签:
1条回答
  • 2020-12-01 17:37
    taxonomy(notFormattedTerms.toSeq:_*)
    

    With : _* you virtually transform a sequence argument so that it looks as if a several arguments had been passed to the variable length method. This transformation, however, only works for (ordered?) simple sequence types and, as in this case, not for a Map. Therefore, one will have to use an explicit toSeq before.

    0 讨论(0)
提交回复
热议问题