sealed trait Schema[A] extends AnyRef
A Schema[A]
describes the structure of some data type A
, in terms of case classes,
enumerations (sealed traits), collections, and various primitive types (including not only
Scala's own primitive types, but enhanced with java.time and big integers / decimals).
Schemas models the structure of data types as first class values, so they can be introspected, transformed, and combined using ordinary Scala code, without macros, metaprogramming, or codegen.
There are implicit schemas provided for all standard Scala types, and you can automatically
derive schemas for your own data types by using DeriveSchema.gen[A]
. Whether you write them
by hand by using constructors and operators,
final case class Person(name: String, age: Int) object Person { implicit val personSchema: Schema[Person] = DeriveSchema.gen[Person] }
- Self Type
- Schema[A]
- Alphabetic
- By Inheritance
- Schema
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- abstract type Accessors[Lens[_, _, _], Prism[_, _, _], Traversal[_, _]]
Abstract Value Members
-
abstract
def
annotate(annotation: Any): Schema[A]
Returns a new schema that with
annotation
-
abstract
def
annotations: Chunk[Any]
Chunk of annotations for this schema
-
abstract
def
defaultValue: Either[String, A]
The default value for a
Schema
of typeA
. - abstract def makeAccessors(b: AccessorBuilder): Accessors[Lens, Prism, Traversal]
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
<*>[B](that: Schema[B]): Schema[(A, B)]
A symbolic operator for zip.
-
def
<+>[B](that: Schema[B]): Schema[Either[A, B]]
A symbolic operator for orElseEither.
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
?: Schema[Option[A]]
A symbolic operator for optional.
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def ast: MetaSchema
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
coerce[B](newSchema: Schema[B]): Either[String, Schema[B]]
Convert to Schema[B] iff B and A are homomorphic.
Convert to Schema[B] iff B and A are homomorphic.
This can be used to e.g convert between a case class and it's "generic" representation as a ListMap[String,_]
-
def
diff(thisValue: A, thatValue: A): Patch[A]
Performs a diff between thisValue and thatValue.
Performs a diff between thisValue and thatValue. See zio.schema.Differ for details on the default diff algorithms.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
- def fromDynamic(value: DynamicValue): Either[String, A]
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
migrate[B](newSchema: Schema[B]): Either[String, (A) ⇒ Either[String, B]]
Generate a homomorphism from A to B iff A and B are homomorphic
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
optional: Schema[Option[A]]
Returns a new schema that modifies the type produced by this schema to be optional.
-
def
orElseEither[B](that: Schema[B]): Schema[Either[A, B]]
Returns a new schema that combines this schema and the specified schema together, modeling their either composition.
- def ordering: Ordering[A]
-
def
patch(oldValue: A, diff: Patch[A]): Either[String, A]
Patch value with a Patch.
- def repeated: Schema[Chunk[A]]
- def serializable: Schema[Schema[A]]
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
- def toDynamic(value: A): DynamicValue
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
transform[B](f: (A) ⇒ B, g: (B) ⇒ A)(implicit loc: SourceLocation): Schema[B]
Transforms this
Schema[A]
into aSchema[B]
, by supplying two functions that can transform betweenA
andB
, without possibility of failure. -
def
transformOrFail[B](f: (A) ⇒ Either[String, B], g: (B) ⇒ Either[String, A])(implicit loc: SourceLocation): Schema[B]
Transforms this
Schema[A]
into aSchema[B]
, by supplying two functions that can transform betweenA
andB
(possibly failing in some cases). - def validate(value: A)(implicit schema: Schema[A]): Chunk[ValidationError]
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
zip[B](that: Schema[B]): Schema[(A, B)]
Returns a new schema that combines this schema and the specified schema together, modeling their tuple composition.