MCPcopy Create free account
hub / github.com/Effect-TS/effect / withDecodingDefault

Function withDecodingDefault

packages/effect/src/Schema.ts:6190–6201  ·  view source on GitHub ↗
(
  defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
  options?: DecodingDefaultOptions
)

Source from the content-addressed store, hash-verified

6188 * @since 3.10.0
6189 */
6190export function withDecodingDefault<S extends Constraint, R = never>(
6191 defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
6192 options?: DecodingDefaultOptions
6193): (self: S) => withDecodingDefault<S, R> {
6194 const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
6195 return (self: S): withDecodingDefault<S, R> => {
6196 return optional(toEncoded(self)).pipe(decodeTo(self, {
6197 decode: SchemaGetter.withDefault(toIssueEffect(defaultValue)),
6198 encode
6199 }))
6200 }
6201}
6202/**
6203 * Type-level representation returned by {@link withDecodingDefaultType}.
6204 *

Callers 1

withDecodingDefaultTypeFunction · 0.70

Calls 6

toIssueEffectFunction · 0.85
optionalInterface · 0.70
toEncodedInterface · 0.70
decodeToFunction · 0.70
omitMethod · 0.65
pipeMethod · 0.65

Tested by

no test coverage detected