c

morphling

OneOfSchema

final case class OneOfSchema[P[_], F[_], I](alts: NonEmptyList[Alt[F, I, _]], discriminator: Option[String] = None) extends SchemaF[P, F, I] with Product with Serializable

Constructor that enables creation of schema for sum types.

Each constructor of the sum type I is represented as a member of the list of alternatives. Each alternative defines a prism between a single constructor of the sum type, and an underlying type describing the arguments demanded by that constructor.

Consider the following sum type. The first constructor takes no arguments; the second takes two.

sealed trait Role

case object User extends Role
case class Administrator(department: String, subordinateCount: Int) extends Role

A schema value for this type looks like:

val roleSchema = oneOf(
  alt[Unit, Prim, Role, Unit](
    "user",
    Schema.empty,
    (_: Unit) => User,
    {
      case User => Some(Unit)
      case _ => None
    }
  ) ::
  alt[Unit, Prim, Role, Administrator](
    "administrator",
    rec[Prim, Administrator](
      (
        required("department", Prim.str, (_: Administrator).department),
        required("subordinateCount", Prim.int, (_: Administrator).subordinateCount)
      ).mapN(Administrator.apply)
    ),
    identity,
    {
      case a @ Administrator(_, _) => Some(a)
      case _ => None
    }
  ) :: Nil
)
P

The GADT type constructor for a sum type which defines the set of primitive types used in the schema.

F

The functor through which the structure of the schema will be interpreted. This will almost always be a fixpoint type such as morphling.HFix.HCofree, which is used to introduce the ability to create recursive (tree-structured) schema.

I

The type of the Scala value to be produced (or consumed) by an interpreter of the schema. Also known as the "index" type of the schema.

Linear Supertypes
Serializable, Product, Equals, SchemaF[P, F, I], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. OneOfSchema
  2. Serializable
  3. Product
  4. Equals
  5. SchemaF
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new OneOfSchema(alts: NonEmptyList[Alt[F, I, _]], discriminator: Option[String] = None)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. val alts: NonEmptyList[Alt[F, I, _]]
  5. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  6. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
  7. val discriminator: Option[String]
  8. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  9. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  10. def hfmap[G[_]](nt: ~>[F, G]): OneOfSchema[P, G, I]

    HFunctor operation which allows transformation of the functor through which the structure of the schema will be interpreted.

    HFunctor operation which allows transformation of the functor through which the structure of the schema will be interpreted.

    Defining this operation directly on the SchemaF type rather than in morphling.SchemaF.schemaFHFunctor simplifies type inference.

    Definition Classes
    OneOfSchemaSchemaF
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  15. def pmap[Q[_]](nt: ~>[P, Q]): OneOfSchema[Q, F, I]

    HFunctor operation which allows transformation of the primitive algebra of the schema.

    HFunctor operation which allows transformation of the primitive algebra of the schema.

    Defining this operation directly on the SchemaF type rather than in morphling.SchemaF.schemaFHFunctor simplifies type inference.

    Definition Classes
    OneOfSchemaSchemaF
  16. def productElementNames: Iterator[String]
    Definition Classes
    Product
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated @Deprecated
    Deprecated

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from SchemaF[P, F, I]

Inherited from AnyRef

Inherited from Any

Ungrouped