Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.transformfunctioneffect/SchemaTransformation.ts:334
<T, E>(options: {
  readonly decode: (input: E) => T
  readonly encode: (input: T) => E
}): Transformation<T, E>

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

  • Each function receives the input and returns the output directly.
  • Skips None inputs (missing keys) — functions are only called on present values.
  • Does not allocate Effects internally; uses optimized sync path.

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
    })
  )
)
export function transform<T, E>(options: {
  readonly decode: (input: E) => T
  readonly encode: (input: T) => E
}): Transformation<T, E> {
  return new Transformation(
    SchemaGetter.transform(options.decode),
    SchemaGetter.transform(options.encode)
  )
}
Referenced by 23 symbols