Overview of ZIO Schema operations
mainOnce a schema is defined, ZIO Schema provides a rich set of operations to manipulate, transform, and interact with data. These operations allow you to combine schemas, transform data types, handle optionality, perform migrations, and manage data patches. Common categories of operations include:
- Composition: Combining schemas using product (
<*>,zip) or sum (<+>,orElseEither) types. - Transformation: Converting between types using
transformortransformOrFail. - Data Manipulation: Converting to/from
DynamicValueviatoDynamicandfromDynamic. - Validation & Patching: Validating values with
validateand applying changes viadiffandpatch. - Schema Evolution: Migrating data between schemas using
migrateor coercing schemas withcoerce. - Metadata: Accessing the schema's structure via
astor adding metadata viaannotate.
sealed trait Schema[A] {
def ? : Schema[Option[A]]
def <*>[B](that: Schema[B]): Schema[(A, B)]
def <+>[B](that: Schema[B]): Schema[scala.util.Either[A, B]]
def defaultValue: scala.util.Either[String, A]
def annotations: Chunk[Any]
def ast: MetaSchema
def annotate(annotation: Any): Schema[A]
def coerce[B](newSchema: Schema[B]): Either[String, Schema[B]]
def diff(thisValue: A, thatValue: A): Patch[A]
def patch(oldValue: A, diff: Patch[A]): scala.util.Either[String, A]
def fromDynamic(value: DynamicValue): scala.util.Either[String, A]
def makeAccessors(b: AccessorBuilder): Accessors[b.Lens, b.Prism, b.Traversal]
def migrate[B](newSchema: Schema[B]): Either[String, A => scala.util.Either[String, B]]
def optional: Schema[Option[A]]
def ordering: Ordering[A]
def orElseEither[B](that: Schema[B]): Schema[scala.util.Either[A, B]]
def repeated: Schema[Chunk[A]]
def serializable: Schema[Schema[A]]
def toDynamic(value: A): DynamicValue
def transform[B](f: A => B, g: B => A): Schema[B]
def transformOrFail[B](f: A => scala.util.Either[String, B], g: B => scala.util.Either[String, A]): Schema[B]
def validate(value: A)(implicit schema: Schema[A]): Chunk[ValidationError]
def zip[B](that: Schema[B]): Schema[(A, B)]
}