Tests the given JValue against this Pattern, with the
restriction that any Variables that are bound in the
environment must match those values if they are re-used in this Pattern.
Tests the given JValue against this Pattern, with the
restriction that any 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.
The value to test.
The environment augmented with any new Variables
encountered in this Pattern, or None 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 JValue.
Uses this Pattern together with the bindings generated as the result of a
call to matches or evaluate to produce a JValue.
Generally the other generate method is simpler to use.
The new JValue, or None if a required 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 JValue.
Uses this Pattern together with the provided variable bindings to generate a
new JValue.
The new 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" }
Tests the given JValue against this Pattern,
and if it matches returns an object that can be used to retrieve the
values matched by any Variables in the
Pattern.
Tests the given JValue against this Pattern,
and if it matches returns an object that can be used to retrieve the
values matched by any Variables in the
Pattern.
The value to test.
An environment which can be used to look up variable bindings, or None 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 Some(results) => println("The integer was " + intVar(results))
case None => println("It didn't match the pattern")
}
Allows this Pattern to be used in a match expression, with the output
being the environment of Variable bindings
as produced by matches.
Allows this Pattern to be used in a match expression, with the output
being the environment of 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")
}
An object that can be used to either match and extract data from, or generate, JValues.