Package: effect
Module: SchemaAST
AST node for lazy/recursive schemas.
Details
Wraps a thunk (() => AST) that is memoized on first call. Use this to
define recursive or mutually recursive schemas without infinite loops at
construction time.
Example (Defining recursive schema ASTs)
import { Schema, SchemaAST } from "effect"
interface Category {
readonly name: string
readonly children: ReadonlyArray<Category>
}
const Category = Schema.Struct({
name: Schema.String,
children: Schema.Array(Schema.suspend((): Schema.Codec<Category> => Category))
})
// The recursive branch is a Suspend node
See
isSuspendSignature
declare class Suspend { constructor(
thunk: () => AST,
annotations?: Schema.Annotations.Annotations,
checks?: Checks,
encoding?: Encoding,
context?: Context
) }
Since v3.10.0