Allows

zio.blocks.schema.comptime.Allows
See theAllows companion class

Attributes

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

Members list

Type members

Classlikes

sealed abstract class Dynamic extends Structural

Matches DynamicValue — the schema-less escape hatch. No further constraint is imposed on the value.

Matches DynamicValue — the schema-less escape hatch. No further constraint is imposed on the value.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class IsType[A] extends Structural

Nominal type predicate. IsType[A] is satisfied only when the Scala type being checked is exactly A (i.e. checked =:= A).

Nominal type predicate. IsType[A] is satisfied only when the Scala type being checked is exactly A (i.e. checked =:= A).

This is the building block for precise element-type constraints. The canonical use-case is constraining the element type of a polymorphic DSL method so that no separate type-alignment proof (e.g. a Containable type class) is needed:

import zio.blocks.schema.comptime.Allows
import Allows._
import zio.blocks.typeid.IsNominalType

trait ConditionExpression[From]

trait Column[From, To] {
 // `To` must be a Set whose element type is exactly `A`.
 // `IsNominalType[A]` ensures A is concrete at the call site.
 def contains[A: IsNominalType](a: A)(implicit
   ev: Allows[To, Sequence.Set[IsType[A]]]
 ): ConditionExpression[From]
}

IsType[A] can also replace specific primitive nodes as type aliases:

import zio.blocks.schema.comptime.Allows._

type MyInt = IsType[scala.Int]  // equivalent to Primitive.Int semantically

Requires that A is a concrete nominal type. Combining with IsNominalType[A] (from zio-blocks-typeid) at the call site ensures the macro always sees a concrete A.

Type parameters

A

The exact Scala type that must match.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class Map[K <: Structural, V <: Structural] extends Structural

Matches a map type (Map, HashMap, …) whose key type satisfies K and whose value type satisfies V.

Matches a map type (Map, HashMap, …) whose key type satisfies K and whose value type satisfies V.

Type parameters

K

The constraint that the key type of the map must satisfy.

V

The constraint that the value type of the map must satisfy.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class Optional[A <: Structural] extends Structural

Matches Option[A] where the inner type satisfies A. Option is handled as a dedicated grammar node rather than being auto-unwrapped as a two-case sealed trait.

Matches Option[A] where the inner type satisfies A. Option is handled as a dedicated grammar node rather than being auto-unwrapped as a two-case sealed trait.

Type parameters

A

The constraint that the inner (unwrapped) type of the Option must satisfy.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class Primitive extends Structural

Catch-all grammar node: matches any of the 30 Schema primitive types.

Catch-all grammar node: matches any of the 30 Schema primitive types.

For stricter control, use the type aliases in Primitive.Int, Primitive.String, etc. — each is defined as IsType[X] for the corresponding Scala/Java type, and is handled by the same IsType macro path. A type that satisfies Primitive.Int also satisfies Primitive via the union check; no special subtype relationship is required.

import zio.blocks.schema.comptime.Allows._

// Allow only JSON-representable numbers:
type JsonNumber = Primitive.Int | Primitive.Long | Primitive.Double

// Allow any primitive (the traditional usage):
type AnyPrim = Primitive

In Scala 2 you may also write Primitive.Int `|` Primitive.Long.

Attributes

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

Attributes

Companion
class
Source
Allows.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Primitive.type
sealed abstract class Record[A <: Structural] extends Structural

Matches a record (case class / product type) whose every field satisfies A. Vacuously true for zero-field records (case objects / enum singletons).

Matches a record (case class / product type) whose every field satisfies A. Vacuously true for zero-field records (case objects / enum singletons).

Type parameters

A

The constraint that every field of the record must satisfy.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class Self extends Structural

Recursive self-reference. When used inside a grammar expression, Self refers back to the entire enclosing Allows[…, S] constraint, allowing the grammar to describe recursive data structures.

Recursive self-reference. When used inside a grammar expression, Self refers back to the entire enclosing Allows[…, S] constraint, allowing the grammar to describe recursive data structures.

Mutual recursion between two or more distinct types is a compile-time error.

Non-recursive types satisfy Self-containing grammars without issue: since the Self position is never reached, the constraint is vacuously satisfied.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class Sequence[A <: Structural] extends Structural

Matches any sequence type (List, Vector, Set, Array, Chunk, …) whose element type satisfies A.

Matches any sequence type (List, Vector, Set, Array, Chunk, …) whose element type satisfies A.

Use the subtypes in Sequence.List, Sequence.Vector, Sequence.Set, Sequence.Array, and Sequence.Chunk when you need to distinguish a specific collection kind. Each subtype extends Sequence[A], so a grammar written with the parent still accepts all collections.

import zio.blocks.schema.comptime.Allows
import Allows._

// Any collection of primitives:
implicitly[Allows[List[Int], Sequence[Primitive]]]

// Only a Set, not a List:
implicitly[Allows[Set[Int], Sequence.Set[Primitive]]]

// Only a Set, and the element type must be exactly Int:
implicitly[Allows[Set[Int], Sequence.Set[IsType[Int]]]]

Type parameters

A

The constraint that the element type of the sequence must satisfy.

Attributes

Companion
object
Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
Known subtypes
class Array[A]
class Chunk[A]
class List[A]
class Set[A]
class Vector[A]
object Sequence

Attributes

Companion
class
Source
Allows.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Sequence.type
sealed abstract class Structural

Root of the grammar type hierarchy. All shape descriptors extend this.

Root of the grammar type hierarchy. All shape descriptors extend this.

Attributes

Source
Allows.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Dynamic
class IsType[A]
class Map[K, V]
class Optional[A]
class Primitive
class Record[A]
class Self
class Sequence[A]
class Array[A]
class Chunk[A]
class List[A]
class Set[A]
class Vector[A]
class Wrapped[A]
class A | B
Show all
sealed abstract class Wrapped[A <: Structural] extends Structural

Matches a wrapper / newtype / opaque type whose underlying type satisfies A.

Matches a wrapper / newtype / opaque type whose underlying type satisfies A.

Type parameters

A

The constraint that the underlying type of the wrapper must satisfy.

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any
sealed abstract class |[A <: Structural, B <: Structural] extends Structural

Union of two grammar nodes. Write in infix position: A | B.

Union of two grammar nodes. Write in infix position: A | B.

In Scala 3 the native union type syntax A | B is also accepted and produces identical semantics with a more concise spelling. In Scala 2, write A `|` B in infix position.

For three-or-more alternatives, chain: A `|` B `|` C.

Type parameters

A

The left-hand grammar node alternative.

B

The right-hand grammar node alternative. Example (both Scala 2 infix and Scala 3 native produce the same grammar):

import zio.blocks.schema.comptime.Allows
import Allows._
// `Allows._` brings the `Map` grammar node into scope, so name Scala's `Map` as `Predef.Map`
case class Person(name: String, emails: List[String], phones: Predef.Map[String, String])
implicitly[Allows[Person, Record[Primitive | Sequence[Primitive] | Map[Primitive, Primitive]]]]

Attributes

Source
Allows.scala
Supertypes
class Structural
class Object
trait Matchable
class Any

Value members

Concrete fields

Single public singleton reused by the macro at every successful call site via a cast. This eliminates any per-call-site allocation.

Single public singleton reused by the macro at every successful call site via a cast. This eliminates any per-call-site allocation.

Attributes

Source
Allows.scala

Givens

Inherited givens

inline given derived: [S <: Structural, A] => Allows[A, S]