Patch

zio.blocks.schema.patch.Patch
See thePatch companion object
final case class Patch[S]

A type-safe patch that can be applied to values of type S.

Patches represent a sequence of operations (set, increment, append, etc.) that transform values. Because patches use serializable operations and reflective optics for navigation, they can be serialized and applied remotely.

Patches can be composed using ++ and applied using the apply method with a PatchMode (Strict, Lenient, or Clobber) to control error handling behavior. Empty patches act as identity (no-op).

import zio.blocks.schema.patch.Patch

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 patch1 = Patch.set(Person.name, "John")
val patch2 = Patch.increment(Person.age, 1)

val patch3 = patch1 ++ patch2

patch3(Person("Jane", 25)) // Person("John", 26)

Value parameters

dynamicPatch

The untyped patch operations

schema

The schema for type S, enabling type-safe conversion

Attributes

Companion
object
Source
Patch.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def ++(that: Patch[S]): Patch[S]

Compose two patches. The result applies this patch first, then that patch.

Compose two patches. The result applies this patch first, then that patch.

Attributes

Source
Patch.scala
def apply(value: S, mode: PatchMode): Either[SchemaError, S]

Attributes

Source
Patch.scala
def apply(s: S): S

Attributes

Source
Patch.scala
def applyOption(s: S): Option[S]

Apply this patch, returning None if any operation fails.

Apply this patch, returning None if any operation fails.

Attributes

Source
Patch.scala
def isEmpty: Boolean

Check if this patch is empty (no operations).

Check if this patch is empty (no operations).

Attributes

Source
Patch.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
Patch.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