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.
Bind this variable into an environment.
Bind this variable into an environment. This is usually used with Pattern#generate.
val intVar = Variable[Int]
val pattern = PObject("i" -> intVar)
println(pattern.generate(intVar := 5)) // { "i" : 5 }
Possibly this variable into an environment.
Possibly this variable into an environment. This is usually used with Pattern#generate.
val intVar = Variable[Int]
val pattern = PObject("i" -> POption(intVar))
println(pattern.generate(intVar :=? Some(5))) // { "i" : 5 }
println(pattern.generate(intVar :=? None)) // { }
Look up the value of this variable in an environment.
Look up the value of this variable in an environment.
The value found
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" }
Look up the value of this variable in an environment.
Look up the value of this variable in an environment.
The value found, or None if it was not bound.
Look up the value of this variable in an environment.
Look up the value of this variable in an environment.
The value found, or alternative if it was not bound.
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")
}
A Pattern which matches any JValue which can be decoded into an object of type
T. If this variable is already bound in the environment at match-time, then this matches only if the two decoded objects areequal, in which case the environment is unchanged.