<T, R = never>(
f: (
input: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>
): Getter<T, T, R>Creates a getter that validates a value using an effectful check function.
When to use
Use when you need a schema getter to validate a decoded value (e.g. check a constraint or call an external service).
- The validation may be asynchronous or require Effect services.
Details
- Only runs when input is
Some—Nonepasses through. - The check function returns a validation result:
undefinedortrue— value is valid, passes through.falseor astring— value is invalid, fails with anIssue.- An
Issueobject — fails with that issue directly. { path, issue }— fails with a nested path issue (issuemay be a message string or a full SchemaIssue.Issue).
- Does not transform the value — input and output types are the same.
Example (Validating effectfully)
import { Effect, SchemaGetter } from "effect"
const nonNegative = SchemaGetter.checkEffect<number>((n) =>
Effect.succeed(n >= 0 ? undefined : "must be non-negative")
)export function function checkEffect<T, R = never>(
f: (
input: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<
undefined | boolean | Schema.FilterIssue,
never,
R
>
): Getter<T, T, R>
Creates a getter that validates a value using an effectful check function.
When to use
Use when you need a schema getter to validate a decoded value (e.g. check a
constraint or call an external service).
- The validation may be asynchronous or require Effect services.
Details
- Only runs when input is
Some — None passes through.
- The check function returns a validation result:
undefined or true — value is valid, passes through.
false or a string — value is invalid, fails with an Issue.
- An
Issue object — fails with that issue directly.
{ path, issue } — fails with a nested path issue (issue may be a
message string or a full
SchemaIssue.Issue
).
- Does not transform the value — input and output types are the same.
Example (Validating effectfully)
import { Effect, SchemaGetter } from "effect"
const nonNegative = SchemaGetter.checkEffect<number>((n) =>
Effect.succeed(n >= 0 ? undefined : "must be non-negative")
)
checkEffect<function (type parameter) T in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>T, function (type parameter) R in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>R = never>(
f: (
input: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<
undefined | boolean | Schema.FilterIssue,
never,
R
>
f: (input: Tinput: function (type parameter) T in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>T, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options: import SchemaASTSchemaAST.type SchemaAST.ParseOptions = /*unresolved*/ anyParseOptions) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<
undefined | boolean | import SchemaSchema.type Schema.FilterIssue = /*unresolved*/ anyFilterIssue,
never,
function (type parameter) R in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>R
>
): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
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; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<function (type parameter) T in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>T, function (type parameter) T in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>T, function (type parameter) R in checkEffect<T, R = never>(f: (input: T, options: SchemaAST.ParseOptions) => Effect.Effect<undefined | boolean | Schema.FilterIssue, never, R>): Getter<T, T, R>R> {
return function onSome<T, E, R = never>(
f: (
e: E,
options: SchemaAST.ParseOptions
) => Effect.Effect<
Option.Option<T>,
SchemaIssue.Issue,
R
>
): Getter<T, E, R>
Creates a getter that handles present values (Option.Some), passing None through.
When to use
Use when you need a schema getter to transform or validate only when a field
value is present.
- Missing keys should remain absent in the output.
Details
- When input is
None, returns None (no-op).
- When input is
Some(e), calls f(e, options) to produce the result.
f may return None to omit the value, or fail with an Issue.
Example (Transforming only present values)
import { Effect, Option, SchemaGetter } from "effect"
const parseIfPresent = SchemaGetter.onSome<number, string>(
(s) => Effect.succeed(Option.some(Number(s)))
)
onSome((t: Tt, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options) => {
return f: (
input: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<
undefined | boolean | Schema.FilterIssue,
never,
R
>
f(t: Tt, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options).pipe(import EffectEffect.flatMapEager((out: anyout) => {
const const issue: SchemaIssue.Issue | undefinedissue = import SchemaIssueSchemaIssue.function makeSingle(
input: unknown,
out: undefined | boolean | Schema.FilterIssue
): Issue | undefined
makeSingle(t: Tt, out: anyout)
return const issue: SchemaIssue.Issue | undefinedissue ?
import EffectEffect.fail(const issue: SchemaIssue.Issueissue) :
import EffectEffect.succeed(import OptionOption.some(t: Tt))
}))
})
}