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

Function optionalOption

packages/effect/src/unstable/schema/Model.ts:314–323  ·  view source on GitHub ↗
(schema: S)

Source from the content-addressed store, hash-verified

312 * @since 4.0.0
313 */
314export const optionalOption = <S extends Schema.Constraint>(schema: S): optionalOption<S> =>
315 Schema.optionalKey(Schema.NullOr(schema)).pipe(
316 Schema.decodeTo(
317 Schema.Option(Schema.toType(schema)),
318 SchemaTransformation.transformOptional<Option.Option<S["Type"]>, S["Type"] | null>({
319 decode: (oe) => oe.pipe(Option.filter(Predicate.isNotNull), Option.some),
320 encode: Option.flatten
321 }) as any
322 )
323 )
324
325/**
326 * Convert a field to one that is optional for all variants.

Callers

nothing calls this directly

Calls 3

filterMethod · 0.80
pipeMethod · 0.65
optionalKeyMethod · 0.65

Tested by

no test coverage detected