Hyperlinkv0.8.0-beta.28

Schema

Schema.OptionFromNullOrfunctioneffect/Schema.ts:8616
OptionFromNullOr<S>

Decodes a nullable, required value T to a required Option<T> value.

Details

Decoding maps null to None and all other values to Some. Encoding maps None to null and maps Some to its value.

Option
Source effect/Schema.ts:861621 lines
export interface OptionFromNullOr<S extends Constraint> extends decodeTo<Option<toType<S>>, NullOr<S>> {
  readonly "Rebuild": OptionFromNullOr<S>
}

/**
 * Decodes a nullable, required value `T` to a required `Option<T>` value.
 *
 * **Details**
 *
 * Decoding maps `null` to `None` and all other values to `Some`. Encoding maps
 * `None` to `null` and maps `Some` to its value.
 *
 * @category Option
 * @since 3.10.0
 */
export function OptionFromNullOr<S extends Constraint>(schema: S): OptionFromNullOr<S> {
  return NullOr(schema).pipe(decodeTo(
    Option(toType(schema)),
    SchemaTransformation.optionFromNullOr()
  ))
}