Sequence

zio.blocks.schema.Reflect.Sequence
See theSequence companion object
case class Sequence[F[_, _], A, C[_]](element: Reflect[F, A], typeId: TypeId[C[A]], seqBinding: F[Seq[C], C[A]], doc: Doc = ..., modifiers: Seq[Reflect] = ..., storedDefaultValue: Option[DynamicValue] = ..., storedExamples: Seq[DynamicValue] = ...) extends Reflect[F, C[A]]

A node for a collection C[A] of elements of type A, such as List[A], Vector[A] or Set[A].

Value parameters

element

the node of the element type

seqBinding

a Binding.Seq with the constructor and deconstructor of C in a bound reflect, NoBinding in an unbound one

storedDefaultValue

the default value, stored as a DynamicValue

storedExamples

the examples, stored as DynamicValues

Attributes

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

Members list

Type members

Types

type NodeBinding = Seq[C]

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 = C[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 asSequence(implicit ev: IsCollection[C[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
def binding(implicit F: HasBinding[F]): Binding[Seq[C], C[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(value: => C[A])(implicit F: HasBinding[F]): Sequence[F, A, C]

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
def doc(value: Doc): Sequence[F, A, C]

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
def elemClassTag: ClassTag[A]

Returns the class tag of the element type, taken from the element's type ID.

Returns the class tag of the element type, taken from the element's type ID.

Attributes

Source
Reflect.scala
def examples(implicit F: HasBinding[F]): Seq[C[A]]

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
def examples(value: C[A], values: C[A]*)(implicit F: HasBinding[F]): Sequence[F, A, C]

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
def getDefaultValue(implicit F: HasBinding[F]): Option[C[A]]

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
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
def metadata: F[NodeBinding, C[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): Sequence[F, A, C]

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
def modifiers(modifiers: Iterable[Reflect]): Sequence[F, A, C]

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
def nodeType: Sequence[C]

Returns the kind of this node, such as Reflect.Type.Record.

Returns the kind of this node, such as Reflect.Type.Record.

Attributes

Source
Reflect.scala
def seqConstructor(implicit F: HasBinding[F]): SeqConstructor[C]

Returns the constructor from the binding, which builds a C from elements.

Returns the constructor from the binding, which builds a C from elements.

Attributes

Source
Reflect.scala
def seqDeconstructor(implicit F: HasBinding[F]): SeqDeconstructor[C]

Returns the deconstructor from the binding, which iterates over the elements of a C.

Returns the deconstructor from the binding, which iterates over the elements of a C.

Attributes

Source
Reflect.scala
def toDynamicValue(value: C[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[Sequence[G, A, C]]

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
def typeId(value: TypeId[C[A]]): Sequence[F, A, C]

Returns a copy of this node whose type ID is value.

Returns a copy of this node whose type ID is value.

Attributes

Source
Reflect.scala

Inherited methods

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

Inherited from:
Reflect
Source
Reflect.scala
def asMap(implicit ev: IsMap[C[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

Inherited from:
Reflect
Source
Reflect.scala
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

Inherited from:
Reflect
Source
Reflect.scala
def asPrimitive: Option[Primitive[F, C[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

Inherited from:
Reflect
Source
Reflect.scala
def asRecord: Option[Record[F, C[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

Inherited from:
Reflect
Source
Reflect.scala
def asTerm[S](name: String): Term[F, S, C[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 asVariant: Option[Variant[F, C[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

Inherited from:
Reflect
Source
Reflect.scala
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

Inherited from:
Reflect
Source
Reflect.scala
def aspect[B, Min >: B, Max <: B](optic: Optic[C[A], B], aspect: SchemaAspect[Min, Max, F]): Reflect[F, C[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 >: C[A], Max <: C[A]](aspect: SchemaAspect[Min, Max, F]): Reflect[F, C[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, C[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
override def equals(obj: Any): Boolean

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
def fromDynamicValue(value: DynamicValue)(implicit F: HasBinding[F]): Either[SchemaError, C[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[C[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
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
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 isDynamic: Boolean

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
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 isMap: Boolean

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
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 isPrimitive: Boolean

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
def isRecord: Boolean

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
def isVariant: Boolean

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
def isWrapper: Boolean

Returns true when this is a Reflect.Wrapper node.

Returns true when this is a Reflect.Wrapper node.

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, C[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[C[A], B])(f: Reflect[F, B] => Reflect[F, B]): Option[Reflect[F, C[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

Inherited fields

lazy val noBinding: Reflect[NoBinding, C[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