<S>(self: S): $Array<S>const const ArraySchema: ArrayLambdaArraySchema = import Struct_Struct_.const lambda: <ArrayLambda>(
f: (a: Constraint) => $Array<Constraint>
) => ArrayLambda
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda<ArrayLambda>((schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema) =>
const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(new import SchemaASTSchemaAST.constructor Arrays(isMutable: boolean, elements: ReadonlyArray<SchemaAST.AST>, rest: ReadonlyArray<SchemaAST.AST>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context, encodingChecks?: SchemaAST.Checks): SchemaAST.ArraysAST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays(false, [], [schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema.Constraint["ast"]: SchemaAST.ASTast]), { value: Constraint(property) value: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
value: schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema })
)