zio.blocks.schema.comptime
Members list
Type members
Classlikes
A compile-time capability token that proves type A satisfies the grammar shape S.
A compile-time capability token that proves type A satisfies the grammar shape S.
Allows[A, S] is an upper bound: any type whose structure is a strict subset of S also satisfies it. A type that uses only some of the allowed shapes trivially passes. This is analogous to a subtype bound.
Allows does not require or use Schema[A]. It inspects the Scala type structure of A directly at compile time. Any Schema[A] that appears alongside Allows in examples is the library author's own separate constraint — it is not imposed by Allows itself.
Type parameters
- A
-
The Scala data type being validated.
- S
-
The grammar shape that
Amust satisfy. Must be a subtype of Allows.Structural. ==Usage (Scala 3)==// scala-3-only import zio.blocks.schema.comptime.Allows import Allows._ // Shape constraint alone — no Schema required def validate[A](v: A)(using Allows[A, Record[Primitive]]): Boolean = ??? // Specific primitives only (e.g. JSON: no Char, UUID, java.time types) type JsonPrimitive = Primitive.Boolean | Primitive.Int | Primitive.Long | Primitive.Float | Primitive.Double | Primitive.String | Primitive.BigInt | Primitive.BigDecimal | Primitive.Unit def toJson[A](doc: A)(using Allows[A, Record[JsonPrimitive | Self]]): String = ??? // Combined with Schema when runtime encoding is also needed def writeCsv[A: Schema](rows: Seq[A])(using Allows[A, Record[Primitive | Optional[Primitive]]] ): Unit = ???==Usage (Scala 2)== Scala 2 lacks native union types. Use the
`|`[A, B]type from theAllowscompanion written in infix position to express unions:import zio.blocks.schema.comptime.Allows import Allows._ def writeCsv[A: Schema](rows: Seq[A])(implicit ev: Allows[A, Record[Primitive | Optional[Primitive]]] ): Unit = ???==Grammar nodes==
- Allows.Primitive — any primitive scalar; or use a specific subtype such as Allows.Primitive$.Int to restrict to a single kind
- Allows.Record — a product type (case class); fields must satisfy
A. Sealed traits and enums are automatically unwrapped: each case is checked individually against the grammar, soVariantis not needed. - Allows.Sequence — any collection (List, Vector, Set, Array, Chunk, …); elements satisfy
A. Use the subtypes inSequence.List,Sequence.Set,Sequence.Vector,Sequence.Array, andSequence.Chunkto narrow to a specific collection kind. - Allows.IsType — nominal type predicate; satisfied only when the Scala type is exactly
A(=:=). Used as an element constraint to align a polymorphic type parameter with the element type of a collection, e.g.Sequence.Set[IsType[A]]. - Allows.Map — a key-value map; keys satisfy
K, values satisfyV - Allows.Optional —
Option[A]; inner type satisfiesA - Allows.Wrapped — a newtype / opaque type; underlying type satisfies
A - Allows.Dynamic —
DynamicValue; no further constraint - Allows.Self — recursive self-reference back to the root grammar
- Allows.| — union of two grammar nodes; write as
A | Bin infix position
Attributes
- Companion
- object
- Source
- Allows.scala
- Supertypes
Attributes
- Companion
- class
- Source
- Allows.scala
- Supertypes
- Self type
-
Allows.type
Attributes
- Source
- AllowsCompanionVersionSpecific.scala
- Supertypes
- Known subtypes
-
object Allows