Binding

zio.blocks.schema.binding.Binding
See theBinding companion trait

The binding kinds, ready-made bindings for standard types, and Binding.of, which derives a binding at compile time.

Attributes

Companion
trait
Source
Binding.scala
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Show all
Self type
Binding.type

Members list

Type members

Classlikes

final case class Dynamic() extends Binding[Dynamic, DynamicValue]

The binding of a dynamic node, which holds a zio.blocks.schema.DynamicValue as it is. It is a marker without data, and all instances are equal.

The binding of a dynamic node, which holds a zio.blocks.schema.DynamicValue as it is. It is a marker without data, and all instances are equal.

Attributes

Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Map[M[_, _], +K, +V](constructor: MapConstructor[M], deconstructor: MapDeconstructor[M]) extends Binding[Map[M], M[K, V]]

The binding of a map node for the map type constructor M: constructor builds an M[K, V] entry by entry, and deconstructor reads one back as its entries. Neither depends on K or V, so one binding serves every key and value type.

The binding of a map node for the map type constructor M: constructor builds an M[K, V] entry by entry, and deconstructor reads one back as its entries. Neither depends on K or V, so one binding serves every key and value type.

Attributes

Companion
object
Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Map[M], M[K, V]]
class Object
trait Matchable
class Any
Show all
object Map

Map bindings for the standard maps.

Map bindings for the standard maps.

Attributes

Companion
class
Source
Binding.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Map.type
final case class Primitive[A]() extends Binding[Primitive, A]

The binding of a primitive node. It is a marker without data: a primitive value is read and written as it is, so there is nothing to construct. All instances are equal. The companion object has one for each of the 30 primitive types.

The binding of a primitive node. It is a marker without data: a primitive value is read and written as it is, so there is nothing to construct. All instances are equal. The companion object has one for each of the 30 primitive types.

Attributes

Companion
object
Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Primitive, A]
class Object
trait Matchable
class Any
Show all
object Primitive

The primitive bindings, one per primitive type.

The primitive bindings, one per primitive type.

Attributes

Companion
class
Source
Binding.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Primitive.type
final case class Record[A](constructor: Constructor[A], deconstructor: Deconstructor[A]) extends Binding[Record, A]

The binding of a record node, such as a case class. constructor builds a value from Registers, and deconstructor writes a value's fields into them.

The binding of a record node, such as a case class. constructor builds a value from Registers, and deconstructor writes a value's fields into them.

Both must use the layout that Reflect.Record#registers computes from the node's fields. In field order, a field stored as a Boolean, Byte, Short, Char, Int, Float, Long or Double takes the next position of its size in the byte area, a Unit field takes no space, and every other field takes the next object slot (see Register). Reflect.Record#fromDynamicValue and #toDynamicValue move each field through that layout, so a binding with a different layout reads the wrong registers.

Attributes

Companion
object
Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Record, A]
class Object
trait Matchable
class Any
Show all
object Record

Record bindings for Option, Either and Maybe cases.

Record bindings for Option, Either and Maybe cases.

Attributes

Companion
class
Source
Binding.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Record.type
final case class Seq[C[_], +A](constructor: SeqConstructor[C], deconstructor: SeqDeconstructor[C]) extends Binding[Seq[C], C[A]]

The binding of a sequence node for the collection type constructor C: constructor builds a C[A] element by element, and deconstructor reads one back as its elements and size. Neither depends on the element type A, so one binding serves every element type, which is why BindingResolver stores sequence bindings by C alone.

The binding of a sequence node for the collection type constructor C: constructor builds a C[A] element by element, and deconstructor reads one back as its elements and size. Neither depends on the element type A, so one binding serves every element type, which is why BindingResolver stores sequence bindings by C alone.

Attributes

Companion
object
Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Seq[C], C[A]]
class Object
trait Matchable
class Any
Show all
object Seq

Sequence bindings for the standard collections.

Sequence bindings for the standard collections.

Attributes

Companion
class
Source
Binding.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Seq.type
final case class Variant[A](discriminator: Discriminator[A], matchers: Matchers[A]) extends Binding[Variant, A]

The binding of a variant node, such as a sealed trait or an enum. discriminator returns the index of the case that a value belongs to, and matchers holds one Matcher per case. Both follow the order of the node's cases: case i of the node is matched by matchers(i), and its values are discriminated as i.

The binding of a variant node, such as a sealed trait or an enum. discriminator returns the index of the case that a value belongs to, and matchers holds one Matcher per case. Both follow the order of the node's cases: case i of the node is matched by matchers(i), and its values are discriminated as i.

Attributes

Companion
object
Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Variant, A]
class Object
trait Matchable
class Any
Show all
object Variant

Variant bindings for Option, Either and Maybe.

Variant bindings for Option, Either and Maybe.

Attributes

Companion
class
Source
Binding.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Variant.type
final case class Wrapper[A, B](wrap: B => A, unwrap: A => B) extends Binding[Wrapper[A, B], A]

The binding of a wrapper node, which stores a value of type A as the value of type B inside it, such as a newtype or the result of Schema#transform. wrap builds an A from a B, and unwrap returns the B inside an A.

The binding of a wrapper node, which stores a value of type A as the value of type B inside it, such as a newtype or the result of Schema#transform. wrap builds an A from a B, and unwrap returns the B inside an A.

wrap rejects a B by throwing. Reflect#fromDynamicValue and the JSON codec catch a non-fatal exception from it and report it as a decoding error.

Type parameters

A

the wrapper type

B

the wrapped type

Attributes

Source
Binding.scala
Supertypes
trait Serializable
trait Product
trait Equals
trait Binding[Wrapper[A, B], A]
class Object
trait Matchable
class Any
Show all

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements.

The names of the product elements.

Attributes

Inherited from:
Mirror
Source
Mirror.scala
type MirroredLabel <: String

The name of the type.

The name of the type.

Attributes

Inherited from:
Mirror
Source
Mirror.scala

Value members

Inherited methods

inline def of[M[_, _]](using mc: MapConstructor[M], md: MapDeconstructor[M]): Map[M, Nothing, Nothing]

Creates a Binding.Map for a map type constructor from the implicit MapConstructor and MapDeconstructor instances. The resulting binding has key and value types Nothing, which upcast via covariance.

Creates a Binding.Map for a map type constructor from the implicit MapConstructor and MapDeconstructor instances. The resulting binding has key and value types Nothing, which upcast via covariance.

Type parameters

M

the map type constructor (e.g., Map)

Attributes

Inherited from:
BindingCompanionVersionSpecific
Source
BindingCompanionVersionSpecific.scala
inline def of[F[_]](using sc: SeqConstructor[F], sd: SeqDeconstructor[F]): Seq[F, Nothing]

Creates a Binding.Seq for a sequence type constructor from the implicit SeqConstructor and SeqDeconstructor instances. The resulting binding has element type Nothing, which upcasts to any element type via covariance.

Creates a Binding.Seq for a sequence type constructor from the implicit SeqConstructor and SeqDeconstructor instances. The resulting binding has element type Nothing, which upcasts to any element type via covariance.

Type parameters

F

the sequence type constructor (e.g., List, Vector)

Attributes

Inherited from:
BindingCompanionVersionSpecific
Source
BindingCompanionVersionSpecific.scala
transparent inline def of[A]: Binding[_, A]

Derives a Binding for type A at compile time.

Derives a Binding for type A at compile time.

Supports:

  • Primitive types (Int, String, Boolean, etc.)
  • Case classes and tuples (derives Binding.Record)
  • Case objects and enum cases without parameters (derives a Binding.Record that always returns the object)
  • Sealed traits, sealed abstract classes and enums (derives Binding.Variant)
  • Option, Either, and their subtypes
  • zio.blocks.schema.DynamicValue
  • A class with one field whose companion has an apply from the field's type to Either[E, A] (derives a Binding.Wrapper whose wrap calls apply and throws a SchemaError on a Left)
  • Structural types, on the JVM only
  • zio-prelude newtypes (derives Binding.Wrapper)
  • On Scala 3 only: named tuples (derives Binding.Record), union types (derives Binding.Variant, with the cases sorted by the full name of each case's type, not in the order the union is written) and opaque types (derives Binding.Wrapper)

On Scala 3, a structural record type needs a build of this library with Scala 3.5 or later; a union of structural types does not. Both Scala 3 artifacts are such builds (zio-blocks-schema with Scala 3.9, zio-blocks-next-schema with Scala 3.10). (In 0.0.56, zio-blocks-schema was built with Scala 3.3 and rejected structural record types at compile time.)

For sequence types (List, Vector, etc.) and map types, use the overloads that take type constructors: Binding.of[List], Binding.of[Map]; Binding.of[List[Int]] does not compile.

Type parameters

A

the type to derive a binding for

Attributes

Returns

the derived binding

Inherited from:
BindingCompanionVersionSpecific
Source
BindingCompanionVersionSpecific.scala

Implicits

Implicits

The FromBinding instance for Binding itself, which returns the binding unchanged.

The FromBinding instance for Binding itself, which returns the binding unchanged.

Attributes

Source
Binding.scala

The HasBinding instance for Binding itself: binding returns its argument, and updateBinding applies the function to it.

The HasBinding instance for Binding itself: binding returns its argument, and updateBinding applies the function to it.

Attributes

Source
Binding.scala