Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.makeconsteffect/SchemaTransformation.ts:233
<T, E, RD = never, RE = never>(options: {
  readonly decode: SchemaGetter.Getter<T, E, RD>
  readonly encode: SchemaGetter.Getter<E, T, RE>
}): Transformation<T, E, RD, RE>

Constructs a Transformation from an object with decode and encode Getters. If the input is already a Transformation, returns it as-is.

When to use

Use when you already have schema getter instances and want to pair them into a schema transformation.

  • You want idempotent wrapping (won't double-wrap).

Details

Example (Wrapping existing getters)

import { SchemaGetter, SchemaTransformation } from "effect"

const t = SchemaTransformation.make({
  decode: SchemaGetter.transform<number, string>((s) => Number(s)),
  encode: SchemaGetter.transform<string, number>((n) => String(n))
})
export const make = <T, E, RD = never, RE = never>(options: {
  readonly decode: SchemaGetter.Getter<T, E, RD>
  readonly encode: SchemaGetter.Getter<E, T, RE>
}): Transformation<T, E, RD, RE> => {
  if (isTransformation(options)) {
    return options as any
  }
  return new Transformation(options.decode, options.encode)
}
Referenced by 3 symbols