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

Function withDecodingDefault

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

Source from the content-addressed store, hash-verified

5991 * @since 3.10.0
5992 */
5993export function withDecodingDefault<S extends Constraint, R = never>(
5994 defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>,
5995 options?: DecodingDefaultOptions
5996) {
5997 const encode = options?.encodingStrategy === "omit" ? SchemaGetter.omit() : SchemaGetter.passthrough()
5998 return (self: S): withDecodingDefault<S, R> => {
5999 return optional(toEncoded(self)).pipe(decodeTo(self, {
6000 decode: SchemaGetter.withDefault(toIssueEffect(defaultValue)),
6001 encode
6002 }))
6003 }
6004}
6005
6006/**
6007 * Type-level representation returned by {@link withDecodingDefaultType}.

Callers 1

withDecodingDefaultTypeFunction · 0.70

Calls 6

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

Tested by

no test coverage detected