Package: effect
Module: SchemaTransformation
Creates a Transformation where decode and encode operate on Option
values, giving full control over missing-key handling.
When to use
Use when you need a schema transformation to produce or consume Option.None
for absent keys.
Details
Option<input> and returns Option<output>.Option.None input means the key is absent; returning Option.None
omits the key from the output.Example (Converting an optional key to Option)
import { Option, Schema, SchemaTransformation } from "effect"
const schema = Schema.Struct({
a: Schema.optionalKey(Schema.Number).pipe(
Schema.decodeTo(
Schema.Option(Schema.Number),
SchemaTransformation.transformOptional({
decode: Option.some,
encode: Option.flatten
})
)
)
})
See
transform — when you don’t need Option-level controloptionFromOptionalKey — built-in for the common optional-key-to-Option patternoptionFromOptional — built-in for optional (undefined) to OptionSignature
declare const transformOptional: <T, E>(options: { readonly decode: (input: Option.Option<E>) => Option.Option<T>; readonly encode: (input: Option.Option<T>) => Option.Option<E>; }) => Transformation<T, E>
Since v4.0.0