(options?: {
readonly separator?: string | undefined
readonly keyValueSeparator?: string | undefined
}): Transformation<Record<string, string>, string>Transforms a string into a record of key-value pairs and encodes a record of key-value pairs into a string.
When to use
Use when you need a schema transformation to parse query-string-like or config-file-like strings into records.
Details
Decoding splits the string by separator (default ",") into pairs, then
splits each pair by keyValueSeparator (default "="). Encoding joins the
record back into a string using the same separators. The transformation is
round-trippable when keys and values do not contain the separators.
Example (Parsing key-value pairs)
import { Schema, SchemaTransformation } from "effect"
const Config = Schema.String.pipe(
Schema.decodeTo(
Schema.Record(Schema.String, Schema.String),
SchemaTransformation.splitKeyValue({ separator: ";", keyValueSeparator: ":" })
)
)
// "host:localhost;port:3000" → { host: "localhost", port: "3000" }export function function splitKeyValue(options?: {
readonly separator?: string | undefined
readonly keyValueSeparator?: string | undefined
}): Transformation<Record<string, string>, string>
Transforms a string into a record of key-value pairs and
encodes a record of key-value pairs into a string.
When to use
Use when you need a schema transformation to parse query-string-like or
config-file-like strings into records.
Details
Decoding splits the string by separator (default ",") into pairs, then
splits each pair by keyValueSeparator (default "="). Encoding joins the
record back into a string using the same separators. The transformation is
round-trippable when keys and values do not contain the separators.
Example (Parsing key-value pairs)
import { Schema, SchemaTransformation } from "effect"
const Config = Schema.String.pipe(
Schema.decodeTo(
Schema.Record(Schema.String, Schema.String),
SchemaTransformation.splitKeyValue({ separator: ";", keyValueSeparator: ":" })
)
)
// "host:localhost;port:3000" → { host: "localhost", port: "3000" }
splitKeyValue(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options?: {
readonly separator?: string | undefinedseparator?: string | undefined
readonly keyValueSeparator?: string | undefinedkeyValueSeparator?: string | undefined
}): 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<type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, string>, string> {
return new constructor Transformation<Record<string, string>, string, never, never>(decode: SchemaGetter.Getter<Record<string, string>, string, never>, encode: SchemaGetter.Getter<string, Record<string, string>, never>): Transformation<Record<string, string>, string, 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.splitKeyValue(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options),
import SchemaGetterSchemaGetter.joinKeyValue(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options)
)
}