<T>(options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined
readonly formatter?: Formatter<T> | undefined
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<T>Creates a divisibility check for any numeric type from a remainder function and a zero value.
export function function makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}): (
divisor: T,
annotations?: Annotations.Filter
) => SchemaAST.Filter<T>
Creates a divisibility check for any numeric type from a remainder function
and a zero value.
makeIsMultipleOf<function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T>(options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}
options: {
readonly remainder: (input: T, divisor: T) => Tremainder: (input: Tinput: function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T, divisor: Tdivisor: function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T) => function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T
readonly zero: NoInfer<T>zero: type NoInfer<T> = intrinsicMarker for non-inference type position
NoInfer<function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T>
readonly annotate?: | ((divisor: T) => Annotations.Filter)
| undefined
annotate?: ((divisor: Tdivisor: function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T) => Annotations.interface Annotations.FilterAnnotations for filter schema nodes (created via Schema.filter). Extends
Augment
with an optional error message, identifier, and metadata.
Filters are intentionally non-parametric to keep them covariant.
Filter) | undefined
readonly formatter?: Formatter<T> | undefinedformatter?: import FormatterFormatter<function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T> | undefined
}) {
return (divisor: Tdivisor: function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T, annotations: Annotations.Filter | undefinedannotations?: Annotations.interface Annotations.FilterAnnotations for filter schema nodes (created via Schema.filter). Extends
Augment
with an optional error message, identifier, and metadata.
Filters are intentionally non-parametric to keep them covariant.
Filter) => {
const const formatter: anyformatter = options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}
options.formatter?: Formatter<T> | undefinedformatter ?? import formatformat
return const makeFilter: <T>(
filter: (
input: T,
ast: SchemaAST.AST,
options: SchemaAST.ParseOptions
) => FilterOutput,
annotations?: Annotations.Filter | undefined,
abort?: boolean
) => SchemaAST.Filter<T>
Creates a custom validation filter from a predicate function.
Details
The predicate receives the decoded input value, the schema AST, and parse
options, and returns a FilterOutput. Non-success outputs are normalized into
schema issues. The annotations parameter annotates the filter itself; with
the default formatter, failures use message first, expected second, and
<filter> when neither is provided.
When abort is true, parsing stops after this filter fails instead of
collecting later check failures.
Example (Reporting failure at a nested path)
import { Schema } from "effect"
const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
Schema.makeFilter((o) =>
o.password === o.confirmPassword
? undefined
: { path: ["password"], issue: "password and confirmPassword must match" }
)
)
console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
// Failure(Cause([Fail(SchemaError: password and confirmPassword must match
// at ["password"])]))
Example (Reporting multiple failures at once)
import { Schema } from "effect"
const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
Schema.makeFilter((o) => {
const issues: Array<Schema.FilterIssue> = []
if (o.a > 0) {
if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
}
return issues
})
)
console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
// Failure(Cause([Fail(SchemaError: b must be greater than 0
// at ["b"]
// c must be greater than 0
// at ["c"])]))
makeFilter<function (type parameter) T in makeIsMultipleOf<T>(options: {
readonly remainder: (input: T, divisor: T) => T;
readonly zero: NoInfer<T>;
readonly annotate?: ((divisor: T) => Annotations.Filter) | undefined;
readonly formatter?: Formatter<T> | undefined;
}): (divisor: T, annotations?: Annotations.Filter) => SchemaAST.Filter<...>
T>(
(input: Tinput) => options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}
options.remainder: (input: T, divisor: T) => Tremainder(input: Tinput, divisor: Tdivisor) === options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}
options.zero: Tzero,
{
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: `a value that is a multiple of ${const formatter: anyformatter(divisor: Tdivisor)}`,
...options: {
readonly remainder: (input: T, divisor: T) => T
readonly zero: NoInfer<T>
readonly annotate?:
| ((divisor: T) => Annotations.Filter)
| undefined
readonly formatter?: Formatter<T> | undefined
}
options.annotate?: | ((divisor: T) => Annotations.Filter)
| undefined
annotate?.(divisor: Tdivisor),
...annotations: Annotations.Filter | undefinedannotations
}
)
}
}