A node for a type A that wraps a value of type B, such as an opaque type or a type built with Schema#transform. A has the DynamicValue form of B: toDynamicValue unwraps the value, and fromDynamicValue decodes a B and wraps it, returning a ConversionFailed error at .wrapped when the wrap function throws.
Value parameters
- storedDefaultValue
-
the default value, stored as a DynamicValue
- storedExamples
-
the examples, stored as DynamicValues
- wrapped
-
the node of the wrapped type
B - wrapperBinding
-
a
Binding.Wrapperwith the wrap and unwrap functions in a bound reflect,NoBindingin an unbound one
Attributes
- Companion
- object
- Source
- Reflect.scala
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait Reflectable[A]class Objecttrait Matchableclass AnyShow all
- Self type
-
Members list
Type members
Types
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
The type that this reflect describes.
Value members
Concrete methods
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
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
Returns a copy of this node whose default value is value, replacing any it had. Every node except Reflect.Deferred evaluates value and stores it as a DynamicValue when this method is called.
Returns a copy of this node whose default value is value, replacing any it had. Every node except Reflect.Deferred evaluates value and stores it as a DynamicValue when this method is called.
Attributes
- Source
- Reflect.scala
Returns a copy of this node whose documentation is value, replacing any it had.
Returns a copy of this node whose documentation is value, replacing any it had.
Attributes
- Source
- Reflect.scala
Returns the examples stored on this node. They are stored as DynamicValues, and an example that does not decode with this reflect is left out.
Returns the examples stored on this node. They are stored as DynamicValues, and an example that does not decode with this reflect is left out.
Attributes
- Source
- Reflect.scala
Returns a copy of this node whose examples are value and values, replacing any it had.
Returns a copy of this node whose examples are value and values, replacing any it had.
Attributes
- Source
- Reflect.scala
Returns the default value stored on this node, or None when it has none or the stored value does not decode with this reflect.
Returns the default value stored on this node, or None when it has none or the stored value does not decode with this reflect.
Attributes
- Source
- Reflect.scala
Returns true when this is a Reflect.Wrapper node.
Returns true when this is a Reflect.Wrapper node.
Attributes
- Definition Classes
- Source
- Reflect.scala
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
Returns a copy of this node with modifier added after its other modifiers.
Returns a copy of this node with modifier added after its other modifiers.
Attributes
- Source
- Reflect.scala
Returns a copy of this node with modifiers added after its other modifiers.
Returns a copy of this node with modifiers added after its other modifiers.
Attributes
- Source
- Reflect.scala
Returns the kind of this node, such as Reflect.Type.Record.
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
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
Rebuilds this reflect with f, which replaces what each node holds, an F, with a G. f sees the children of a node already transformed, and path is the location of this node: f receives it, extended by the field, case, elements, map-keys or map-values step of each child (a wrapped node keeps the path of its wrapper). f is not called until the result is forced.
Rebuilds this reflect with f, which replaces what each node holds, an F, with a G. f sees the children of a node already transformed, and path is the location of this node: f receives it, extended by the field, case, elements, map-keys or map-values step of each child (a wrapped node keeps the path of its wrapper). f is not called until the result is forced.
For a Reflect.Deferred node, the result is cached per thread under that node and f, which is what makes a recursive type terminate. A Deferred node reached by several paths in one scope is transformed once, with the path of the first. noBinding, DynamicSchema#rebind and type class derivation clear that cache when they return. A direct call leaves its entries in the cache, and so does the first use of a Deferred node in any result after the call has returned, because that is when the node's value is transformed.
Attributes
- See also
- Source
- Reflect.scala
Returns a copy of this node whose type ID is value.
Returns the primitive type behind typeId when it is an opaque type or type alias of a primitive type, or is itself one; otherwise None.
Returns the primitive type behind typeId when it is an opaque type or type alias of a primitive type, or is itself one; otherwise None.
Attributes
- Source
- Reflect.scala
Inherited methods
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
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
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
Returns true when obj is a reflect with the same structure, such as the same child nodes, type ID, documentation and modifiers. Bindings, default values and examples are not compared.
Returns true when obj is a reflect with the same structure, such as the same child nodes, type ID, documentation and modifiers. Bindings, default values and examples are not compared.
Attributes
- Definition Classes
-
Reflect -> Any
- Inherited from:
- Reflect
- Source
- Reflect.scala
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.Variantwhose case name it knows. - a sequence expects a
DynamicValue.Sequence, and a map aDynamicValue.Map. - a primitive expects a
DynamicValue.Primitive; numeric types andCharalso accept other numeric orCharvalues that convert to them, without loss except for the cases listed atPrimitiveType#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
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
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
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
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
Returns true when this is a Reflect.Dynamic node.
Returns true when this is a Reflect.Dynamic node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
Returns true when this is a Reflect.Map node.
Returns true when this is a Reflect.Map node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
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
Returns true when this is a Reflect.Primitive node.
Returns true when this is a Reflect.Primitive node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
Returns true when this is a Reflect.Record node.
Returns true when this is a Reflect.Record node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
Returns true when this is a Reflect.Sequence node.
Returns true when this is a Reflect.Sequence node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
Returns true when this is a Reflect.Variant node.
Returns true when this is a Reflect.Variant node.
Attributes
- Inherited from:
- Reflect
- Source
- Reflect.scala
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
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
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
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
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
Inherited fields
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