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

Function withDecodingDefaultKey

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

Source from the content-addressed store, hash-verified

6077 * @since 4.0.0
6078 */
6079export function withDecodingDefaultKey<S extends Constraint, R = never>(
6080 defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
6081 options?: DecodingDefaultOptions
6082): (self: S) => withDecodingDefaultKey<S, R> {
6083 const fallback = Effect.mapEager(toIssueEffect(defaultValue), Option_.some)
6084 const decode = SchemaGetter.transformOptionalEffect((input: Option_.Option<S["Encoded"]>) =>
6085 Option_.isSome(input) ? Effect.succeed(input) : fallback
6086 )
6087 const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
6088 return (self: S): withDecodingDefaultKey<S, R> =>
6089 optionalKey(toEncoded(self)).pipe(decodeTo(self, { decode, encode }))
6090}
6091/**
6092 * Type-level representation returned by {@link withDecodingDefaultTypeKey}.
6093 *

Callers 2

tagDefaultOmitFunction · 0.70

Calls 7

toIssueEffectFunction · 0.85
optionalKeyInterface · 0.85
toEncodedInterface · 0.70
decodeToFunction · 0.70
omitMethod · 0.65
pipeMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected