Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Created August 17, 2012 20:06
Show Gist options
  • Save matthandlersux/3382144 to your computer and use it in GitHub Desktop.
Save matthandlersux/3382144 to your computer and use it in GitHub Desktop.
pulling out types?
class Test {
def pullOutType[V](f:Map[String, V] => Unit) {
var map = Map[String, V]()
val params = Map("string" -> "string", "int" -> 20, "list" -> List("ok", "then"))
params.foreach {
case (field, value) => value match {
case v:V => map = map + (field -> v)
case _ => null
}
case _ => null
}
f(map)
}
}
val x = new Test
x.pullOutType[List[String]] { data:Map[String, List[String]] =>
assert(data.size == 2)
}
x.pullOutType { data:Map[String, String] =>
assert(data.first == "string")
}
x.pullOutType { data:Map[String, Int] =>
assert(data.first == 20)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment