effect-io-ai

Package: effect
Module: SchemaTransformation

SchemaTransformation.transform

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

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

Signature

declare const transform: <T, E>(options: { readonly decode: (input: E) => T; readonly encode: (input: T) => E; }) => Transformation<T, E>

Source

Since v3.10.0