DerivationBuilder

zio.blocks.schema.derive.DerivationBuilder
final case class DerivationBuilder[TC[_], A](schema: Schema[A], deriver: Deriver[TC], instanceOverrides: IndexedSeq[InstanceOverride], modifierOverrides: IndexedSeq[ModifierOverride])

A DerivationBuilder is capable of deriving a type class instance for any data type that has a schema. Though instances for all substructures can be derived automatically, you can also specify instances for specific substructures using the instance method, and modifiers for them using the modifier method.

import zio.blocks.schema.json._

case class Person(name: String, age: Int)
object Person extends CompanionOptics[Person] {
 implicit val schema: Schema[Person] = Schema.derived
 val name: Lens[Person, String] = $(_.name)
 val age: Lens[Person, Int]     = $(_.age)
}

val personCodec: JsonCodec[Person] = Person.schema
 .deriving(JsonCodecDeriver)
 .instance(Person.age, JsonCodec.intCodec)
 .modifier(Person.name, Modifier.rename("fullName"))
 .derive

Attributes

Source
DerivationBuilder.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def instance[B](optic: Optic[A, B], instance: => TC[B]): DerivationBuilder[TC, A]

Overrides the type class instance at an exact path in the schema tree identified by optic. This is the most precise override: it targets one specific location.

Overrides the type class instance at an exact path in the schema tree identified by optic. This is the most precise override: it targets one specific location.

Attributes

Source
DerivationBuilder.scala
def instance[B](typeId: TypeId[B], instance: => TC[B]): DerivationBuilder[TC, A]

Overrides the type class instance for every occurrence of the type identified by typeId, regardless of where it appears in the schema tree. This is the least precise override.

Overrides the type class instance for every occurrence of the type identified by typeId, regardless of where it appears in the schema tree. This is the least precise override.

Attributes

Source
DerivationBuilder.scala
def instance[P, B](typeId: TypeId[P], termName: String, instance: => TC[B]): DerivationBuilder[TC, A]

Overrides the type class instance for a term (record field or variant case) identified by termName inside a parent record or variant identified by typeId. This is a medium-precision override between optic-based (exact path) and type-based (all occurrences).

Overrides the type class instance for a term (record field or variant case) identified by termName inside a parent record or variant identified by typeId. This is a medium-precision override between optic-based (exact path) and type-based (all occurrences).

The typeId refers to the parent record/variant type, not the field type. The field type B is not statically checked against the actual term type. If no term with the given name exists in the parent type, the override is silently ignored.

Attributes

Source
DerivationBuilder.scala
def modifier[B](typeId: TypeId[B], modifier: Reflect): DerivationBuilder[TC, A]

Adds a reflect-level modifier for every occurrence of the type identified by typeId.

Adds a reflect-level modifier for every occurrence of the type identified by typeId.

Attributes

Source
DerivationBuilder.scala
def modifier[B](optic: Optic[A, B], modifier: Modifier): DerivationBuilder[TC, A]

Adds a modifier at an exact path in the schema tree identified by optic. Accepts both Modifier.Reflect (applied to the node itself) and Modifier.Term (applied to the terminal field or case at the end of the optic path).

Adds a modifier at an exact path in the schema tree identified by optic. Accepts both Modifier.Reflect (applied to the node itself) and Modifier.Term (applied to the terminal field or case at the end of the optic path).

Attributes

Source
DerivationBuilder.scala
def modifier[B](typeId: TypeId[B], termName: String, modifier: Term): DerivationBuilder[TC, A]

Adds a term-level modifier for a field or variant case identified by termName inside a parent type identified by typeId. The typeId refers to the parent record/variant type that owns the term, not the term's own type. If no term with the given name exists in the parent type, the modifier is silently ignored.

Adds a term-level modifier for a field or variant case identified by termName inside a parent type identified by typeId. The typeId refers to the parent record/variant type that owns the term, not the term's own type. If no term with the given name exists in the parent type, the modifier is silently ignored.

Attributes

Source
DerivationBuilder.scala

Inherited methods

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

Concrete fields

lazy val derive: TC[A]

Attributes

Source
DerivationBuilder.scala