Package: effect
Module: SchemaTransformation
Creates a Transformation from pure (sync, infallible) decode and encode
functions.
When to use
Use when you need an infallible schema transformation that does not require Effect services.
Details
None inputs (missing keys) — functions are only called on present values.Example (Converting between cents and dollars)
import { Schema, SchemaTransformation } from "effect"
const CentsFromDollars = Schema.Number.pipe(
Schema.decodeTo(
Schema.Number,
SchemaTransformation.transform({
decode: (dollars) => dollars * 100,
encode: (cents) => cents / 100
})
)
)
See
transformOrFail — for fallible or effectful transformationstransformOptional — for transformations that handle missing keyspassthrough — when no conversion is neededSignature
declare const transform: <T, E>(options: { readonly decode: (input: E) => T; readonly encode: (input: T) => E; }) => Transformation<T, E>
Since v3.10.0