Skip to content

Instantly share code, notes, and snippets.

@fmpwizard
Created July 13, 2011 04:36
Show Gist options
  • Save fmpwizard/1079726 to your computer and use it in GitHub Desktop.
Save fmpwizard/1079726 to your computer and use it in GitHub Desktop.
def updateCity(x: Any) : JsCmd = {
val (cometName: String, cityId) = Full(x).asA[Map[String, Any]] match {
case Full(m) => (
m.get("cometName").getOrElse("No comet Name"),
m.get("cityId").getOrElse("1")
)
case _ => ("No Comet Name", "1")
}
...
}
@ccmtaylor
Copy link

untested, but this might work and be a little simpler:

updateCity(x: Any) : JsCmd = {
    val (cometName: String, cityId) = x match {
      case m: Map[String, Any]] => (
        m.get("cometName").getOrElse("No comet Name"),
        m.get("cityId").getOrElse("1")
      )
      case _ => ("No Comet Name", "1")
    }
...

@ccmtaylor
Copy link

or even

def updateCity(x: Any) : JsCmd = {
    val (cometName: String, cityId) = Full(x).asA[Map[String, Any]].map { m =>
      (
        m.get("cometName").getOrElse("No comet Name"),
        m.get("cityId").getOrElse("1")
      )
    } openOr ("No Comet Name", "1")
...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment