<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.ParseOptions) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
undefined | boolean | import SchemaSchema.type FilterIssue =
| string
| SchemaIssue.Issue
| {
readonly path: ReadonlyArray<PropertyKey>
readonly issue: string | SchemaIssue.Issue
}
A single failure reported by a filter predicate. Used as the element type
of the array arm of
FilterOutput
, and also accepted on its own.
Details
string: failure with that string as the message. Produces an
SchemaIssue.InvalidValue
wrapping the input, with the string used as
the issue's message annotation.
SchemaIssue.Issue
: a fully-formed issue, returned as-is.
{ path, issue }: failure attached to a nested path. issue is either
a string (wrapped in an
SchemaIssue.InvalidValue
) or a full
SchemaIssue.Issue
; the result is wrapped in an
SchemaIssue.Pointer
at the given path.
FilterIssue,
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).Pipeable.pipe<Effect.Effect<boolean | Schema.FilterIssue | undefined, never, R>, Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>>(this: Effect.Effect<boolean | Schema.FilterIssue | undefined, never, R>, ab: (_: Effect.Effect<boolean | Schema.FilterIssue | undefined, never, R>) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>): Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R> (+21 overloads)pipe(import EffectEffect.const flatMapEager: {
<A, B, E2, R2>(
f: (a: A) => Effect<B, E2, R2>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E | E2, R | R2>
<A, E, R, B, E2, R2>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E2, R2>
): Effect<B, E | E2, R | R2>
}
flatMapEager((out: boolean | Schema.FilterIssue | undefinedout) => {
const const issue: SchemaIssue.Issue | undefinedissue = import SchemaIssueSchemaIssue.function makeSingle(
input: unknown,
out: undefined | boolean | Schema.FilterIssue
): Issue | undefined
makeSingle(t: Tt, out: boolean | Schema.FilterIssue | undefinedout)
return const issue: SchemaIssue.Issue | undefinedissue ?
import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const issue: SchemaIssue.Issueissue) :
import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(t: Tt))
}))
})
}