Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, with the
restriction that any com.rojoma.json.v3.matcher.Variables that are bound in the
environment must match those values if they are re-used in this Pattern.
Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, with the
restriction that any com.rojoma.json.v3.matcher.Variables that are bound in the
environment must match those values if they are re-used in this Pattern.
Generally you won't use this directly, but you can if you want to pre-populate variables.
The value to test.
The environment augmented with any new com.rojoma.json.v3.matcher.Variables
encountered in this Pattern, or Left(error) if it didn't match.
Uses this Pattern together with the bindings generated as the result of a
call to matches or evaluate to produce a com.rojoma.json.v3.ast.JValue.
Uses this Pattern together with the bindings generated as the result of a
call to matches or evaluate to produce a com.rojoma.json.v3.ast.JValue.
Generally the other generate method is simpler to use.
The new com.rojoma.json.v3.ast.JValue, or None if a required com.rojoma.json.v3.matcher.Variable is not bound in the environment, or a matcher which cannot generate is used.
Uses this Pattern together with the provided variable bindings to generate a
new com.rojoma.json.v3.ast.JValue.
Uses this Pattern together with the provided variable bindings to generate a
new com.rojoma.json.v3.ast.JValue.
The new com.rojoma.json.v3.ast.JValue
val intVar = Variable[Int] val strVar = Variable[String] val pattern = PObject("i" -> intVar, "s" -> POption(strVar)) pattern.generate(i := 1) // { "i" : 1 } pattern.generate(i := 1, s := "hello") // { "i" : 1, "s" : "hello" } pattern.generate(i := 1, s :=? None ) // { "i" : 1 } pattern.generate(i := 1, s :=? Some("hello")) // { "i" : 1, "s" : "hello" }
JsonGenerationException if a required com.rojoma.json.v3.matcher.Variable
is not bound or a matcher which cannot generate (such as com.rojoma.json.v3.matcher.AllOf)
is used.
Tests the given com.rojoma.json.v3.ast.JValue against this Pattern,
and if it matches returns an object that can be used to retrieve the
values matched by any com.rojoma.json.v3.matcher.Variables in the
Pattern.
Tests the given com.rojoma.json.v3.ast.JValue against this Pattern,
and if it matches returns an object that can be used to retrieve the
values matched by any com.rojoma.json.v3.matcher.Variables in the
Pattern.
The value to test.
An environment which can be used to look up variable bindings, or Left(error) if it didn't match.
val intVar = Variable[Int] val strVar = Variable[String] val pattern = PObject("i" -> intVar, "s" -> strVar) pattern.matches(jvalue) match { case Right(results) => println("The integer was " + intVar(results)) case Left(_) => println("It didn't match the pattern") }
Allows this Pattern to be used in a match expression, with the output
being the environment of com.rojoma.json.v3.matcher.Variable bindings
as produced by matches.
Allows this Pattern to be used in a match expression, with the output
being the environment of com.rojoma.json.v3.matcher.Variable bindings
as produced by matches.
val intVar = Variable[Int] val strVar = Variable[String] val Pattern1 = PObject("i" -> intVar, "s" -> strVar) val Pattern2 = PObject("hello" -> "world") jvalue match { case Pattern1(results) => println("The integer was " + intVar(results)) case Pattern2(result) => println("It was just a hello world object") case _ => println("It was something else") }
A com.rojoma.json.v3.matcher.Pattern which matches if the value is a com.rojoma.json.v3.ast.JArray which contains at least as many elements as sub-patterns contained by this object and those elements match the sub-patterns in the order given.
For the more common case where a sequence of repeated objects of a particular type is desired, use a com.rojoma.json.v3.matcher.Variable of some
Seq[T].