Class/Object

com.rojoma.json.v3.matcher

Variable

Related Docs: object Variable | package matcher

Permalink

abstract class Variable[T] extends Pattern with PartialFunction[Results, T]

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 are equal, in which case the environment is unchanged.

Linear Supertypes
PartialFunction[Results, T], (Results) ⇒ T, Pattern, OptPattern, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Variable
  2. PartialFunction
  3. Function1
  4. Pattern
  5. OptPattern
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Variable()

    Permalink

Abstract Value Members

  1. abstract def evaluate(x: JValue, environment: Results): Either[DecodeError, Results]

    Permalink

    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.

    x

    The value to test.

    returns

    The environment augmented with any new com.rojoma.json.v3.matcher.Variables encountered in this Pattern, or Left(error) if it didn't match.

    Definition Classes
    Pattern
  2. abstract def generate(environment: Results): Option[JValue]

    Permalink

    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.

    returns

    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.

    Definition Classes
    Pattern

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def :=(x: T): (Results) ⇒ Results

    Permalink

    Bind this variable into an environment.

    Bind this variable into an environment. This is usually used with com.rojoma.json.v3.matcher.Pattern#generate.

    Example:
    1. val intVar = Variable[Int]
      val pattern = PObject("i" -> intVar)
      println(pattern.generate(intVar := 5)) // { "i" : 5 }
  4. def :=?(x: Option[T]): (Results) ⇒ Results

    Permalink

    Possibly this variable into an environment.

    Possibly this variable into an environment. This is usually used with com.rojoma.json.v3.matcher.Pattern#generate.

    Example:
    1. val intVar = Variable[Int]
      val pattern = PObject("i" -> POption(intVar))
      println(pattern.generate(intVar :=? Some(5))) // { "i" : 5 }
      println(pattern.generate(intVar :=? None)) // { }
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def andThen[C](k: (T) ⇒ C): PartialFunction[Results, C]

    Permalink
    Definition Classes
    PartialFunction → Function1
  7. def apply(results: Results): T

    Permalink

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found

    Definition Classes
    Variable → Function1
    Exceptions thrown

    NoSuchElementException if the variable is not bound.

  8. def applyOrElse[A1 <: Results, B1 >: T](x: A1, default: (A1) ⇒ B1): B1

    Permalink
    Definition Classes
    PartialFunction
  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def compose[A](g: (A) ⇒ Results): (A) ⇒ T

    Permalink
    Definition Classes
    Function1
    Annotations
    @unspecialized()
  12. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  14. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  15. def generate(bindings: (Results) ⇒ Results*): JValue

    Permalink

    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.

    returns

    The new com.rojoma.json.v3.ast.JValue

    Definition Classes
    Pattern
    Example:
    1. 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" }
    Exceptions thrown

    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.

  16. def get(results: Results): Option[T]

    Permalink

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found, or None if it was not bound.

  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def getOrElse[U >: T](results: Results, alternative: ⇒ U): U

    Permalink

    Look up the value of this variable in an environment.

    Look up the value of this variable in an environment.

    returns

    The value found, or alternative if it was not bound.

  19. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  20. def isBound(results: Results): Boolean

    Permalink
  21. def isDefinedAt(results: Results): Boolean

    Permalink
    Definition Classes
    Variable → PartialFunction
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. def lift: (Results) ⇒ Option[T]

    Permalink
    Definition Classes
    PartialFunction
  24. def matches(x: JValue): Either[DecodeError, Results]

    Permalink

    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.

    x

    The value to test.

    returns

    An environment which can be used to look up variable bindings, or Left(error) if it didn't match.

    Definition Classes
    Pattern
    Example:
    1. 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")
      }
  25. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  26. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. def orElse[A1 <: Results, B1 >: T](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]

    Permalink
    Definition Classes
    PartialFunction
  29. def runWith[U](action: (T) ⇒ U): (Results) ⇒ Boolean

    Permalink
    Definition Classes
    PartialFunction
  30. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  31. def toString(): String

    Permalink
    Definition Classes
    Function1 → AnyRef → Any
  32. def unapply(x: JValue): Option[Results]

    Permalink

    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.

    Definition Classes
    Pattern
    Example:
    1. 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")
      }
  33. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from PartialFunction[Results, T]

Inherited from (Results) ⇒ T

Inherited from Pattern

Inherited from OptPattern

Inherited from AnyRef

Inherited from Any

Ungrouped