Package: effect
Module: SchemaTransformation
Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts between two representations.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
flip() and compose() return new instances.flip() swaps the decode and encode getters.compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
See
make — construct from { decode, encode } getterstransform — construct from pure functionstransformOrFail — construct from effectful functionsMiddleware — effect-pipeline-level alternativeSignature
declare class Transformation<T, E, RD, RE> { constructor(
decode: SchemaGetter.Getter<T, E, RD>,
encode: SchemaGetter.Getter<E, T, RE>
) }
Since v4.0.0