Safe downcast with a fairly nice syntax.
Safe downcast with a fairly nice syntax. This will statically prevent attempting to cast anywhere except a subclass of the value's static type.
It can be used for navigation in a JSON tree:
for {
JObject(foo) <- raw.cast[JObject]
JArray(elems) <- foo.get("foo").flatMap(_.cast[JArray])
} yield {
...something with elems...
} getOrElse(throw "couldn't find interesting elements")