Dustin Getz
Dustin Getz

Reputation: 21801

how do you destructure a list in scala

I have this code:

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

to which I need to add a dozen more config options, so I was hoping to refactor it to something like:

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)
}

I made that code up. What is the proper syntax to do this? On the map/match line I get this error, which I do not understand:

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

Upvotes: 0

Views: 1494

Answers (1)

Kim Stebel
Kim Stebel

Reputation: 42047

in order to match on a sequence, you can write

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

Upvotes: 4

Related Questions