Package: effect
Module: Schema
Applies a transformation to a schema’s encoded type, creating a new schema where encoding/decoding
operate on S["Encoded"] rather than S["Type"].
Details
The decode getter maps S["Encoded"] → S["Encoded"] (applied during decoding),
and the encode getter maps S["Encoded"] → S["Encoded"] (applied during encoding).
Example (Upper-casing encoded strings)
import { Schema, SchemaGetter } from "effect"
const UpperFromLower = Schema.String.pipe(
Schema.encode({
decode: SchemaGetter.transform((s: string) => s.toLowerCase()),
encode: SchemaGetter.transform((s: string) => s.toUpperCase())
})
)
Signature
declare const encode: <S extends Constraint, RD = never, RE = never>(transformation: { readonly decode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RD>; readonly encode: SchemaGetter.Getter<S["Encoded"], S["Encoded"], RE>; }) => (self: S) => decodeTo<S, toEncoded<S>, RD, RE>
Since v3.10.0