<T, R = never>(
defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>
): Getter<T, T | undefined, R>Creates a getter that replaces undefined values with a default.
When to use
Use when you need a schema getter to provide a fallback for a field that may
be undefined in the encoded input.
Details
- If the input is
Some(undefined)orNone, producesSome(T). - If the input is
Some(value)where value is notundefined, passes it through. defaultValueis anEffectthat will be executed each time a default is needed.
Example (Providing a default value for an optional field)
import { Effect, SchemaGetter } from "effect"
const withZero = SchemaGetter.withDefault(Effect.succeed(0))
// Getter<number, number | undefined>export function function withDefault<T, R = never>(
defaultValue: Effect.Effect<
T,
SchemaIssue.Issue,
R
>
): Getter<T, T | undefined, R>
Creates a getter that replaces undefined values with a default.
When to use
Use when you need a schema getter to provide a fallback for a field that may
be undefined in the encoded input.
Details
- If the input is
Some(undefined) or None, produces Some(T).
- If the input is
Some(value) where value is not undefined, passes it through.
defaultValue is an Effect that will be executed each time a default is needed.
Example (Providing a default value for an optional field)
import { Effect, SchemaGetter } from "effect"
const withZero = SchemaGetter.withDefault(Effect.succeed(0))
// Getter<number, number | undefined>
withDefault<function (type parameter) T in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>T, function (type parameter) R in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>R = never>(
defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>(parameter) defaultValue: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
defaultValue: import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) T in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>T, import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue, function (type parameter) R in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, 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 withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>T, function (type parameter) T in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>T | undefined, function (type parameter) R in withDefault<T, R = never>(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>R> {
return new constructor Getter<T, T | undefined, R>(run: (input: Option.Option<T | undefined>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>): Getter<T, T | undefined, R>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((o: Option.Option<T | undefined>o) => {
const const filtered: Option.Option<
Exclude<T, undefined>
>
filtered = import OptionOption.filter(o: Option.Option<T | undefined>o, import PredicatePredicate.isNotUndefined)
return import OptionOption.isSome(const filtered: Option.Option<
Exclude<T, undefined>
>
filtered) ? import EffectEffect.succeed(const filtered: Option.Some<
Exclude<T, undefined>
>
const filtered: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
filtered) : import EffectEffect.mapEager(defaultValue: Effect.Effect<T, SchemaIssue.Issue, R>(parameter) defaultValue: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
defaultValue, import OptionOption.some)
})
}