I’m trying to understand exactly how the following code snippet works, in particular line 2, Seq(JsString(bar), _*), and line 3, must_, syntax is puzzling to me
val foo = (Json.parse(contentAsString(result)
val Seq(JsString(bar), _*) = (foo \\ "bar")
bar must_== "crazy"
Line 2 is a pattern match, but using
valsyntax.foo \\ "bar"returns aSeq, which you can match on;means that the item must match to a
Seqand the first item must be aJsStringwhose content we will callbar, and we don’t care about the rest (_*). Normally you’d see this like so:but it turns out that you can initialize
vals this way also.Also,
must_==is a method name (methods can be alphanumeric followed by an underscore followed by symbols) for some testing framework. I forget which. But there almost certainly is an implicit conversion from whatever to tested-whatever, and tested-whatever has themust_==method.