Deferred

zio.blocks.schema.Reflect.Deferred
See theDeferred companion object
case class Deferred[F[_, _], A](_value: () => Reflect[F, A], _typeId: Option[TypeId[A]] = ..., deferredDefaultValue: Option[() => A] = ..., deferredExamples: Seq[() => A] = ...) extends Reflect[F, A]

A node that stands for another node, built the first time it is needed. A recursive type uses it to refer to itself: in the derived schema of case class Tree(value: Int, children: List[Tree]), the node of the children field is a Deferred. Derivation also uses it for every field with a default value.

Its methods forward to value, except for the default value and examples set on this node, and the type ID when _typeId is set. The methods that walk the tree stop when they come back to this node: typeId then returns a placeholder named ``, toString prints deferred => and the type ID, equals returns true, and the as* and is* methods return None and false.

Value parameters

_typeId

a type ID to return instead of that node's

_value

builds the node that this one stands for

Attributes

Companion
object
Source
Reflect.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Reflect[F, A]
trait Reflectable[A]
class Object
trait Matchable
class Any
Show all
Self type
Deferred[F, A]

Members list

Type members

Types

type NodeBinding = value.NodeBinding

The kind of binding this node holds, such as BindingType.Record for a record. It fixes the types of metadata and binding.

The kind of binding this node holds, such as BindingType.Record for a record. It fixes the types of metadata and binding.

Attributes

Source
Reflect.scala

Inherited types

final type Structure = A

The type that this reflect describes.

The type that this reflect describes.

Attributes

Inherited from:
Reflect
Source
Reflect.scala

Value members

Concrete methods

override def asDynamic: Option[Dynamic[F]]

Returns this node as a Reflect.Dynamic, or None for another kind of node.

Returns this node as a Reflect.Dynamic, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asMap(implicit ev: IsMap[A]): Option[Map[F, ev.Key, ev.Value, ev.Map]]

Returns this node as a Reflect.Map typed with the key, value and map types that IsMap gives for A, or None for another kind of node.

Returns this node as a Reflect.Map typed with the key, value and map types that IsMap gives for A, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asMapUnknown: Option[Unknown[F]]

Returns this node as a map node whose key, value and map types are not known statically, or None for another kind of node. Use it when A is not known to be a map type.

Returns this node as a map node whose key, value and map types are not known statically, or None for another kind of node. Use it when A is not known to be a map type.

Attributes

Definition Classes
Source
Reflect.scala
override def asPrimitive: Option[Primitive[F, A]]

Returns this node as a Reflect.Primitive, or None for another kind of node.

Returns this node as a Reflect.Primitive, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asRecord: Option[Record[F, A]]

Returns this node as a Reflect.Record, or None for another kind of node.

Returns this node as a Reflect.Record, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asSequence(implicit ev: IsCollection[A]): Option[Sequence[F, ev.Elem, ev.Collection]]

Returns this node as a Reflect.Sequence typed with the element and collection types that IsCollection gives for A, or None for another kind of node.

Returns this node as a Reflect.Sequence typed with the element and collection types that IsCollection gives for A, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asSequenceUnknown: Option[Unknown[F]]

Returns this node as a sequence node whose element and collection types are not known statically, or None for another kind of node. Use it when A is not known to be a collection type.

Returns this node as a sequence node whose element and collection types are not known statically, or None for another kind of node. Use it when A is not known to be a collection type.

Attributes

Definition Classes
Source
Reflect.scala
override def asVariant: Option[Variant[F, A]]

Returns this node as a Reflect.Variant, or None for another kind of node.

Returns this node as a Reflect.Variant, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
override def asWrapperUnknown: Option[Unknown[F]]

Returns this node as a wrapper node whose wrapped type is not known statically, or None for another kind of node.

Returns this node as a wrapper node whose wrapped type is not known statically, or None for another kind of node.

Attributes

Definition Classes
Source
Reflect.scala
def binding(implicit F: HasBinding[F]): Binding[NodeBinding, A]

Returns the Binding of this node: the functions that build and take apart values of A.

Returns the Binding of this node: the functions that build and take apart values of A.

Attributes

Source
Reflect.scala
def defaultValue(dv: => A)(implicit F: HasBinding[F]): Deferred[F, A]

Returns a copy whose default value is dv. Unlike the other nodes, it does not evaluate dv: getDefaultValue evaluates it on every call.

Returns a copy whose default value is dv. Unlike the other nodes, it does not evaluate dv: getDefaultValue evaluates it on every call.

Attributes

Source
Reflect.scala
def doc(value: Doc): Deferred[F, A]

Returns a copy that stands for the node with the documentation value.

Returns a copy that stands for the node with the documentation value.

Attributes

Source
Reflect.scala
def doc: Doc

Returns the documentation of value.

Returns the documentation of value.

Attributes

Source
Reflect.scala
override def equals(obj: Any): Boolean

Checks whether this instance is equal to that. This universal equality method is defined in AnyRef.

Checks whether this instance is equal to that. This universal equality method is defined in AnyRef.

Attributes

Definition Classes
Equals -> Reflect -> Any
Source
Reflect.scala
def examples(implicit F: HasBinding[F]): Seq[A]

Returns the examples set on this node, or else the examples of value.

Returns the examples set on this node, or else the examples of value.

Attributes

Source
Reflect.scala
def examples(value: A, values: A*)(implicit F: HasBinding[F]): Deferred[F, A]

Returns a copy whose examples are value and values, kept as values of A instead of DynamicValues.

Returns a copy whose examples are value and values, kept as values of A instead of DynamicValues.

Attributes

Source
Reflect.scala
def getDefaultValue(implicit F: HasBinding[F]): Option[A]

Returns the default value set on this node, evaluated on each call, or else the default value of value.

Returns the default value set on this node, evaluated on each call, or else the default value of value.

Attributes

Source
Reflect.scala
override def hashCode: Int

Calculates a hash code value for the object.

Calculates a hash code value for the object.

The default hashing algorithm is platform dependent.

Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Attributes

Returns

the hash code value for this object.

Definition Classes
Reflect -> Any
Source
Reflect.scala
override def isDynamic: Boolean

Returns true when this is a Reflect.Dynamic node.

Returns true when this is a Reflect.Dynamic node.

Attributes

Definition Classes
Source
Reflect.scala
override def isMap: Boolean

Returns true when this is a Reflect.Map node.

Returns true when this is a Reflect.Map node.

Attributes

Definition Classes
Source
Reflect.scala
override def isPrimitive: Boolean

Returns true when this is a Reflect.Primitive node.

Returns true when this is a Reflect.Primitive node.

Attributes

Definition Classes
Source
Reflect.scala
override def isRecord: Boolean

Returns true when this is a Reflect.Record node.

Returns true when this is a Reflect.Record node.

Attributes

Definition Classes
Source
Reflect.scala
override def isSequence: Boolean

Returns true when this is a Reflect.Sequence node.

Returns true when this is a Reflect.Sequence node.

Attributes

Definition Classes
Source
Reflect.scala
override def isVariant: Boolean

Returns true when this is a Reflect.Variant node.

Returns true when this is a Reflect.Variant node.

Attributes

Definition Classes
Source
Reflect.scala
override def isWrapper: Boolean

Returns true when this is a Reflect.Wrapper node.

Returns true when this is a Reflect.Wrapper node.

Attributes

Definition Classes
Source
Reflect.scala
def metadata: F[NodeBinding, A]

Returns what this node holds besides its structure: a Binding in a bound reflect, NoBinding in an unbound one.

Returns what this node holds besides its structure: a Binding in a bound reflect, NoBinding in an unbound one.

Attributes

Source
Reflect.scala
def modifier(modifier: Reflect): Deferred[F, A]

Returns a copy that stands for the node with modifier added.

Returns a copy that stands for the node with modifier added.

Attributes

Source
Reflect.scala
def modifiers: Seq[Reflect]

Returns the modifiers of value.

Returns the modifiers of value.

Attributes

Source
Reflect.scala
def modifiers(modifiers: Iterable[Reflect]): Deferred[F, A]

Returns a copy that stands for the node with modifiers added.

Returns a copy that stands for the node with modifiers added.

Attributes

Source
Reflect.scala
def nodeType: Type { type NodeBinding = NodeBinding; }

Returns the kind of value.

Returns the kind of value.

Attributes

Source
Reflect.scala
def toDynamicValue(value: A)(implicit F: HasBinding[F]): DynamicValue

Converts value into a DynamicValue with the same shape as this reflect: a DynamicValue.Record with the fields in declaration order, a DynamicValue.Variant named after the value's case, a DynamicValue.Sequence, a DynamicValue.Map or a DynamicValue.Primitive. A wrapper gives the dynamic value of the value it wraps, and a dynamic node returns value as it is. fromDynamicValue converts the result back.

Converts value into a DynamicValue with the same shape as this reflect: a DynamicValue.Record with the fields in declaration order, a DynamicValue.Variant named after the value's case, a DynamicValue.Sequence, a DynamicValue.Map or a DynamicValue.Primitive. A wrapper gives the dynamic value of the value it wraps, and a dynamic node returns value as it is. fromDynamicValue converts the result back.

case class Book(title: String, year: Int)
object Book {
 implicit val schema: Schema[Book] = Schema.derived
}

val value = Book.schema.reflect.toDynamicValue(Book("Zionomicon", 2021))
// {
//   title: "Zionomicon",
//   year: 2021
// }

Attributes

See also
Source
Reflect.scala
override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
Source
Reflect.scala
def transform[G[_, _]](path: DynamicOptic, f: ReflectTransformer[F, G]): Lazy[Reflect[G, A]]

Returns a deferred node that transforms value with f when it is first needed. The result is cached per thread under this node and f, which is what makes the transformation of a recursive type terminate.

Returns a deferred node that transforms value with f when it is first needed. The result is cached per thread under this node and f, which is what makes the transformation of a recursive type terminate.

Attributes

Source
Reflect.scala
def typeId: TypeId[A]

Returns _typeId when it is set, or else the type ID of value, or the placeholder `` when looking it up comes back to this node.

Returns _typeId when it is set, or else the type ID of value, or the placeholder `` when looking it up comes back to this node.

Attributes

Source
Reflect.scala
def typeId(newTypeId: TypeId[A]): Deferred[F, A]

Returns a copy whose type ID is newTypeId, without building value.

Returns a copy whose type ID is newTypeId, without building value.

Attributes

Source
Reflect.scala

Inherited methods

def asTerm[S](name: String): Term[F, S, A]

Returns a Term named name whose value is this node, to use as a field or case of a record or variant of type S.

Returns a Term named name whose value is this node, to use as a field or case of a record or variant of type S.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def aspect[B, Min >: B, Max <: B](optic: Optic[A, B], aspect: SchemaAspect[Min, Max, F]): Reflect[F, A]

Returns this reflect with aspect applied to the node that optic focuses on, or this reflect unchanged when the optic's path does not lead to a node.

Returns this reflect with aspect applied to the node that optic focuses on, or this reflect unchanged when the optic's path does not lead to a node.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def aspect[Min >: A, Max <: A](aspect: SchemaAspect[Min, Max, F]): Reflect[F, A]

Returns this reflect with the SchemaAspect aspect applied to it.

Returns this reflect with the SchemaAspect aspect applied to it.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def doc(value: String): Reflect[F, A]

Returns a copy of this node whose documentation is value, as a single paragraph of plain text, replacing any it had. doc without an argument reads it back.

Returns a copy of this node whose documentation is value, as a single paragraph of plain text, replacing any it had. doc without an argument reads it back.

case class Book(title: String, year: Int)
object Book {
 implicit val schema: Schema[Book] = Schema.derived
}

val documented = Book.schema.reflect.doc("A book in the catalogue")
val text       = documented.doc.toString.trim // A book in the catalogue

Attributes

See also
Inherited from:
Reflect
Source
Reflect.scala
def fromDynamicValue(value: DynamicValue)(implicit F: HasBinding[F]): Either[SchemaError, A]

Converts value into an A, or returns a SchemaError that lists where value does not fit this reflect. The errors of all the fields, elements and map entries are collected, not only the first one.

Converts value into an A, or returns a SchemaError that lists where value does not fit this reflect. The errors of all the fields, elements and map entries are collected, not only the first one.

Each kind of node expects its own kind of DynamicValue:

  • a record expects a DynamicValue.Record. It matches the fields by name, in any order, and ignores fields it does not know.
  • a variant expects a DynamicValue.Variant whose case name it knows.
  • a sequence expects a DynamicValue.Sequence, and a map a DynamicValue.Map.
  • a primitive expects a DynamicValue.Primitive; numeric types and Char also accept other numeric or Char values that convert to them, without loss except for the cases listed at PrimitiveType#fromDynamicValue.
  • a wrapper decodes the value of the type it wraps, then wraps it.
  • a dynamic node accepts any value as it is.

The errors are ExpectationMismatch for the wrong kind of value, MissingField, DuplicatedField and UnknownCase, each at the path where it happened, and ConversionFailed at a path ending in .wrapped when a wrapper's wrap function throws. A missing field is an error even when the field has a default value, and Validation constraints are not checked (DynamicSchema#check checks them).

case class Book(title: String, year: Int)
object Book {
 implicit val schema: Schema[Book] = Schema.derived
}

val title = DynamicValue.Primitive(PrimitiveValue.String("Zionomicon"))
val year  = DynamicValue.Primitive(PrimitiveValue.Int(2021))

val book = Book.schema.reflect.fromDynamicValue(
 DynamicValue.Record("title" -> title, "year" -> year)
) // Right(Book(Zionomicon,2021))
val missing = Book.schema.reflect.fromDynamicValue(
 DynamicValue.Record("title" -> title)
) // Left(zio.blocks.schema.SchemaError: Missing field 'year' at: .)

Attributes

See also
Inherited from:
Reflect
Source
Reflect.scala
def get(dynamic: DynamicOptic): Option[Reflect[F, _]]

Returns the node at the path dynamic, or None when the path does not lead to a node of this reflect.

Returns the node at the path dynamic, or None when the path does not lead to a node of this reflect.

Each step moves to a child node: a field step to the record field of that name, a case step to the variant case of that name, an index, indices or elements step to the element node of a sequence, a wrapped step to the wrapped node, a map-keys step to the key node of a map, and any other map step to its value node. A type search step moves to the first node, in depth-first order, whose type ID is the searched one, and a schema search step to the first node that matches its pattern; the rest of the path continues from there.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def get[B](optic: Optic[A, B]): Option[Reflect[F, B]]

Returns the node that optic focuses on, or None when the optic's path does not lead to a node of this reflect.

Returns the node that optic focuses on, or None when the optic's path does not lead to a node of this reflect.

case class Author(name: String)
object Author {
 implicit val schema: Schema[Author] = Schema.derived
}

case class Book(title: String, author: Author)
object Book extends CompanionOptics[Book] {
 implicit val schema: Schema[Book]   = Schema.derived
 val authorName: Lens[Book, String] = $(_.author.name)
}

val node = Book.schema.reflect.get(Book.authorName) // Some(String)

Attributes

See also
Inherited from:
Reflect
Source
Reflect.scala
def isCollection: Boolean

Returns true when this is a sequence or map node.

Returns true when this is a sequence or map node.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def isEnumeration: Boolean

Returns true when this is a variant whose cases carry no data: each case is a record without fields, such as a case object, or is itself such a variant.

Returns true when this is a variant whose cases carry no data: each case is a record without fields, such as a case object, or is itself such a variant.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def isMaybe: Boolean

Returns true when this is the variant of a zio.blocks.maybe.Maybe: a variant whose type ID is Maybe, with two cases, the second named Present.

Returns true when this is the variant of a zio.blocks.maybe.Maybe: a variant whose type ID is Maybe, with two cases, the second named Present.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def isOption: Boolean

Returns true when this is the variant of a scala.Option: a variant whose type ID is Option in package scala, with two cases, the second named Some.

Returns true when this is the variant of a scala.Option: a variant whose type ID is Option in package scala, with two cases, the second named Some.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def optionInnerType: Option[Reflect[F, _]]

For an Option or Maybe variant, returns the node of the value it holds: the single field of its Some or Present case. Returns None for any other node.

For an Option or Maybe variant, returns the node of the value it holds: the single field of its Some or Present case. Returns None for any other node.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
Source
Product.scala
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala
def updated[B](dynamic: DynamicOptic)(f: Updater[F]): Option[Reflect[F, A]]

Returns a copy of this reflect in which the node at the path dynamic is replaced by f.update of it, or None when the path does not lead to a node. It follows field, case, sequence, wrapped, map-keys and map-values steps as get does, but it does not run type or schema searches: on a map node a type or schema search step is treated as a map-values step, and on any other node it returns None.

Returns a copy of this reflect in which the node at the path dynamic is replaced by f.update of it, or None when the path does not lead to a node. It follows field, case, sequence, wrapped, map-keys and map-values steps as get does, but it does not run type or schema searches: on a map node a type or schema search step is treated as a map-values step, and on any other node it returns None.

Attributes

Inherited from:
Reflect
Source
Reflect.scala
def updated[B](optic: Optic[A, B])(f: Reflect[F, B] => Reflect[F, B]): Option[Reflect[F, A]]

Returns a copy of this reflect in which the node that optic focuses on is replaced by f of it, or None when the optic's path does not lead to a node of this reflect.

Returns a copy of this reflect in which the node that optic focuses on is replaced by f of it, or None when the optic's path does not lead to a node of this reflect.

Attributes

Inherited from:
Reflect
Source
Reflect.scala

Concrete fields

final lazy val value: Reflect[F, A]

The node that this one stands for, built on first access.

The node that this one stands for, built on first access.

Attributes

Source
Reflect.scala

Inherited fields

lazy val noBinding: Reflect[NoBinding, A]

This reflect without bindings: the same tree, with the metadata of every node replaced by NoBinding. It keeps the structure, documentation, modifiers, default values and examples. Schema#toDynamicSchema wraps it in a DynamicSchema.

This reflect without bindings: the same tree, with the metadata of every node replaced by NoBinding. It keeps the structure, documentation, modifiers, default values and examples. Schema#toDynamicSchema wraps it in a DynamicSchema.

Attributes

Inherited from:
Reflect
Source
Reflect.scala