<T>(schema: Schema<T>): Equivalence.Equivalence<T>Derives an Equivalence from a schema. Two values are considered equal when
every field (and nested field) compares equal according to the schema
structure.
Example (Comparing structs)
import { Schema } from "effect"
const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // falseexport function function toEquivalence<T>(
schema: Schema<T>
): Equivalence.Equivalence<T>
Derives an Equivalence from a schema. Two values are considered equal when
every field (and nested field) compares equal according to the schema
structure.
Example (Comparing structs)
import { Schema } from "effect"
const eq = Schema.toEquivalence(Schema.Struct({ id: Schema.Number, name: Schema.String }))
console.log(eq({ id: 1, name: "Alice" }, { id: 1, name: "Alice" })) // true
console.log(eq({ id: 1, name: "Alice" }, { id: 2, name: "Alice" })) // false
toEquivalence<function (type parameter) T in toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>T>(schema: Schema<T>(parameter) schema: {
Type: T;
Rebuild: Schema<T>;
Iso: Iso;
ast: Ast;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<T, any>) => Schema<T>;
annotateKey: (annotations: Annotations.Key<T>) => Schema<T>;
check: (checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => Schema<T>;
rebuild: (ast: SchemaAST.AST) => Schema<T>;
make: (input: unknown, options?: MakeOptions) => T;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<T>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<T, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema: interface Schema<out T>Namespace of type-level helpers for
Schema
.
A typed view of a schema that tracks only the decoded (output) type T.
Details
Use Schema<T> as a constraint when you want to accept "any schema that
decodes to T" and do not need to know or constrain the encoded
representation, required services, or any other type parameters.
This is a structural interface — concrete schema values are produced by the
constructors in this module (e.g.
Struct
,
String
,
Number
).
When you also need the encoded type or service requirements, use
Codec
.
Example (Accepting any schema decoding to string)
import { Schema } from "effect"
declare function print(schema: Schema.Schema<string>): void
print(Schema.String) // ok
print(Schema.NonEmptyString) // ok
Schema<function (type parameter) T in toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>T>): import EquivalenceEquivalence.type Equivalence.Equivalence = /*unresolved*/ anyEquivalence<function (type parameter) T in toEquivalence<T>(schema: Schema<T>): Equivalence.Equivalence<T>T> {
return import InternalEquivalenceInternalEquivalence.const toEquivalence: anytoEquivalence(schema: Schema<T>(parameter) schema: {
Type: T;
Rebuild: Schema<T>;
Iso: Iso;
ast: Ast;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<T, any>) => Schema<T>;
annotateKey: (annotations: Annotations.Key<T>) => Schema<T>;
check: (checks_0: SchemaAST.Check<T>, ...checks: Array<SchemaAST.Check<T>>) => Schema<T>;
rebuild: (ast: SchemaAST.AST) => Schema<T>;
make: (input: unknown, options?: MakeOptions) => T;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<T>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<T, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>["ast"]: SchemaAST.ASTast)
}