( defaultValue: Effect.Effect<S["Encoded"], SchemaError, R>, options?: DecodingDefaultOptions )
| 6077 | * @since 4.0.0 |
| 6078 | */ |
| 6079 | export 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 | * |
no test coverage detected