Package: effect
Module: SchemaGetter
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation between types.
Schema.decodeTo.Details
Some(e) to Some(f(e)) and leaves None unchanged.None inputs — only called when a value is present.Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
See
transformOrFail when the transformation can failtransformOptional when you need to handle None inputspassthrough when no transformation is neededSignature
declare const transform: <T, E>(f: (e: E) => T) => Getter<T, E>
Since v4.0.0