<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>
readonly encode: (input: Option.Option<T>) => Option.Option<E>
}): Transformation<T, E>Creates a Transformation where decode and encode operate on Option
values, giving full control over missing-key handling.
When to use
Use when you need a schema transformation to produce or consume Option.None
for absent keys.
- You are working with optional struct fields.
Details
- Each function receives
Option<input>and returnsOption<output>. Option.Noneinput means the key is absent; returningOption.Noneomits the key from the output.- Pure and synchronous.
Example (Converting an optional key to Option)
import { Option, Schema, SchemaTransformation } from "effect"
const schema = Schema.Struct({
a: Schema.optionalKey(Schema.Number).pipe(
Schema.decodeTo(
Schema.Option(Schema.Number),
SchemaTransformation.transformOptional({
decode: Option.some,
encode: Option.flatten
})
)
)
})export function function transformOptional<
T,
E
>(options: {
readonly decode: (
input: Option.Option<E>
) => Option.Option<T>
readonly encode: (
input: Option.Option<T>
) => Option.Option<E>
}): Transformation<T, E>
Creates a Transformation where decode and encode operate on Option
values, giving full control over missing-key handling.
When to use
Use when you need a schema transformation to produce or consume Option.None
for absent keys.
- You are working with optional struct fields.
Details
- Each function receives
Option<input> and returns Option<output>.
Option.None input means the key is absent; returning Option.None
omits the key from the output.
- Pure and synchronous.
Example (Converting an optional key to Option)
import { Option, Schema, SchemaTransformation } from "effect"
const schema = Schema.Struct({
a: Schema.optionalKey(Schema.Number).pipe(
Schema.decodeTo(
Schema.Option(Schema.Number),
SchemaTransformation.transformOptional({
decode: Option.some,
encode: Option.flatten
})
)
)
})
transformOptional<function (type parameter) T in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
T, function (type parameter) E in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
E>(options: {
readonly decode: (
input: Option.Option<E>
) => Option.Option<T>
readonly encode: (
input: Option.Option<T>
) => Option.Option<E>
}
options: {
readonly decode: (
input: Option.Option<E>
) => Option.Option<T>
decode: (input: Option.Option<E>input: import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
E>) => import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
T>
readonly encode: (
input: Option.Option<T>
) => Option.Option<E>
encode: (input: Option.Option<T>input: import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) T in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
T>) => import OptionOption.type Option.Option = /*unresolved*/ anyOption<function (type parameter) E in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
E>
}): class Transformation<in out T, in out E, RD = never, RE = never>class Transformation {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => Transformation<E, T, RE, RD>;
compose: <T2, RD2, RE2>(other: Transformation<T2, T, RD2, RE2>) => Transformation<T2, E, RD | RD2, RE | RE2>;
}
Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<function (type parameter) T in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
T, function (type parameter) E in transformOptional<T, E>(options: {
readonly decode: (input: Option.Option<E>) => Option.Option<T>;
readonly encode: (input: Option.Option<T>) => Option.Option<E>;
}): Transformation<T, E>
E> {
return new constructor Transformation<T, E, never, never>(decode: SchemaGetter.Getter<T, E, never>, encode: SchemaGetter.Getter<E, T, never>): Transformation<T, E, never, never>Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation(
import SchemaGetterSchemaGetter.transformOptional(options: {
readonly decode: (
input: Option.Option<E>
) => Option.Option<T>
readonly encode: (
input: Option.Option<T>
) => Option.Option<E>
}
options.decode: (
input: Option.Option<E>
) => Option.Option<T>
decode),
import SchemaGetterSchemaGetter.transformOptional(options: {
readonly decode: (
input: Option.Option<E>
) => Option.Option<T>
readonly encode: (
input: Option.Option<T>
) => Option.Option<E>
}
options.encode: (
input: Option.Option<T>
) => Option.Option<E>
encode)
)
}