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

Function OptionFromOptionalNullOr

packages/effect/src/Schema.ts:9871–9890  ·  view source on GitHub ↗
(
  schema: S,
  options?: {
    readonly onNoneEncoding: "omit" | null | undefined
  }
)

Source from the content-addressed store, hash-verified

9869 * @since 4.0.0
9870 */
9871export function OptionFromOptionalNullOr<S extends Constraint>(
9872 schema: S,
9873 options?: {
9874 readonly onNoneEncoding: "omit" | null | undefined
9875 }
9876): OptionFromOptionalNullOr<S> {
9877 const onNoneEncoding = options === undefined ? "omit" : options.onNoneEncoding
9878 const noneValue = onNoneEncoding === null
9879 ? null as S["Type"] | null | undefined
9880 : undefined as S["Type"] | null | undefined
9881 return optional(NullOr(schema)).pipe(decodeTo(
9882 Option(toType(schema)),
9883 SchemaTransformation.transformOptional<Option_.Option<S["Type"]>, S["Type"] | null | undefined>({
9884 decode: (oe) => oe.pipe(Option_.filter(Predicate.isNotNullish), Option_.some),
9885 encode: onNoneEncoding === "omit"
9886 ? Option_.flatten
9887 : (ot) => Option_.some(Option_.getOrElse(Option_.flatten(ot), () => noneValue))
9888 })
9889 ))
9890}
9891
9892/**
9893 * Type-level representation returned by {@link Result}.

Callers

nothing calls this directly

Calls 8

NullOrInterface · 0.85
toTypeInterface · 0.85
filterMethod · 0.80
someMethod · 0.80
optionalInterface · 0.70
decodeToFunction · 0.70
OptionFunction · 0.70
pipeMethod · 0.65

Tested by

no test coverage detected