Created
August 17, 2012 20:06
-
-
Save matthandlersux/3382144 to your computer and use it in GitHub Desktop.
pulling out types?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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