2012-11-19 53 views
0

名单我有这样的代码:你如何解构在斯卡拉

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 => ? 

回答

4

为了匹配序列,你可以写

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