(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.function splitKeyValue<
E extends string
>(options?: {
readonly separator?: string | undefined
readonly keyValueSeparator?: string | undefined
}): Getter<Record<string, string>, E>
Parses a string into a record of key-value pairs.
When to use
Use when you need a schema getter to parse a present encoded string that
contains delimited key-value pairs (e.g. "a=1,b=2").
Details
The getter is pure and never fails. It splits the string by separator
(default ,) and then each pair by keyValueSeparator (default =). Pairs
missing a key or value are silently skipped.
Example (Parsing a key-value string)
import { SchemaGetter } from "effect"
const parse = SchemaGetter.splitKeyValue<string>()
// "a=1,b=2" -> { a: "1", b: "2" }
splitKeyValue(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options),
import SchemaGetterSchemaGetter.function joinKeyValue<
E extends Record<PropertyKey, string>
>(options?: {
readonly separator?: string | undefined
readonly keyValueSeparator?: string | undefined
}): Getter<string, E>
Joins a record of key-value pairs into a delimited string.
When to use
Use when you need a schema getter to serialize a present decoded record as a
delimited key-value string.
Details
The getter is pure and never fails. It joins entries with separator
(default ,) and joins each key and value with keyValueSeparator (default
=).
Example (Joining key-value records)
import { SchemaGetter } from "effect"
const join = SchemaGetter.joinKeyValue()
// { a: "1", b: "2" } -> "a=1,b=2"
joinKeyValue(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options)
)
}