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.
Bind this variable into an environment.
Bind this variable into an environment. This is usually used with com.rojoma.json.v3.matcher.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 com.rojoma.json.v3.matcher.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
if the variable is not bound.
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" }
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.
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 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 any com.rojoma.json.v3.ast.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.