zio.blocks.schema.comptime

Members list

Type members

Classlikes

sealed abstract class Allows[A, S <: Structural]

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 A must 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 the Allows companion 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, so Variant is not needed.
  • Allows.Sequence — any collection (List, Vector, Set, Array, Chunk, …); elements satisfy A. Use the subtypes in Sequence.List, Sequence.Set, Sequence.Vector, Sequence.Array, and Sequence.Chunk to 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 satisfy V
  • Allows.Optional — Option[A]; inner type satisfies A
  • 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 | B in infix position

Attributes

Companion
object
Source
Allows.scala
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Source
Allows.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Allows.type

Attributes

Source
AllowsCompanionVersionSpecific.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Allows