你如何在scala中构造一个列表

时间:2012-11-19 20:08:22

标签: scala

我有这段代码:

val host:String = Play.configuration.getString("auth.ldap.directory.host").get
val port:java.lang.Integer = Play.configuration.getString("auth.ldap.directory.port").get.toInt
val userDNFormat:String = Play.configuration.getString("auth.ldap.userDNFormat").get

我需要添加十几个配置选项,所以我希望将它重构为:

val params = Seq("auth.ldap.directory.host", "auth.ldap.directory.port", "auth.ldap.userDNFormat")
params.map(Play.configuration.getString) match {
  case host~port~userDNFormat => foo(host, port, userDNFormat)
}

我编写了代码。这样做的正确语法是什么?在地图/匹配行中,我收到此错误,我不明白:

error: type mismatch;
found   : (String, Option[Set[String]]) => Option[String]
required: java.lang.String => ?

1 个答案:

答案 0 :(得分:4)

为了匹配序列,你可以写

case Seq(host, port, userDNFormat) => foo(host, port, userDNFormat)