<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" }export function 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<function (type parameter) E in splitKeyValue<E extends string>(options?: {
readonly separator?: string | undefined;
readonly keyValueSeparator?: string | undefined;
}): Getter<Record<string, string>, E>
E extends string>(options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options?: {
readonly separator?: string | undefinedseparator?: string | undefined
readonly keyValueSeparator?: string | undefinedkeyValueSeparator?: string | undefined
}): class Getter<out T, in E, R = never>class Getter {
run: (input: Option.Option<E>, options: SchemaAST.ParseOptions) => Effect.Effect<Option.Option<T>, SchemaIssue.Issue, R>;
map: <T2>(f: (t: T) => T2) => Getter<T2, E, R>;
compose: <T2, R2>(other: Getter<T2, T, R2>) => Getter<T2, E, R | R2>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Represents a composable transformation from an encoded type E to a decoded type T.
When to use
Use when you need a schema getter to build and compose custom transformations
for Schema.decodeTo or Schema.decode.
Details
A getter wraps a function Option<E> -> Effect<Option<T>, Issue, R>. It
receives Option.None when the encoded key is absent, such as a missing
struct field, and returns Option.None to omit the value from the decoded
output. It fails with Issue on invalid input and may require Effect
services via R. .map(f) applies f to the decoded value inside Some
while leaving None unchanged. .compose(other) chains two getters by
feeding the output of this into other; passthrough getters on either side
are optimized away.
Example (Creating and composing getters)
import { SchemaGetter } from "effect"
const parseNumber = SchemaGetter.transform<number, string>((s) => Number(s))
const double = SchemaGetter.transform<number, number>((n) => n * 2)
const composed = parseNumber.compose(double)
// composed: Getter<number, string> — parses then doubles
Getter<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>, function (type parameter) E in splitKeyValue<E extends string>(options?: {
readonly separator?: string | undefined;
readonly keyValueSeparator?: string | undefined;
}): Getter<Record<string, string>, E>
E> {
const const separator: stringseparator = options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options?.separator?: string | undefinedseparator ?? ","
const const keyValueSeparator: stringkeyValueSeparator = options: | {
readonly separator?: string | undefined
readonly keyValueSeparator?:
| string
| undefined
}
| undefined
options?.keyValueSeparator?: string | undefinedkeyValueSeparator ?? "="
return function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
transform((input: E extends stringinput) =>
input: E extends stringinput.String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)Split a string into substrings using the specified separator and return them as an array.
split(const separator: stringseparator).Array<string>.reduce<Record<string, string>>(callbackfn: (previousValue: Record<string, string>, currentValue: string, currentIndex: number, array: string[]) => Record<string, string>, initialValue: Record<string, string>): Record<string, string> (+2 overloads)Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
reduce((acc: Record<string, string>acc, pair: stringpair) => {
const [const key: stringkey, const value: stringvalue] = pair: stringpair.String.split(separator: string | RegExp, limit?: number): string[] (+1 overload)Split a string into substrings using the specified separator and return them as an array.
split(const keyValueSeparator: stringkeyValueSeparator)
if (const key: stringkey && const value: stringvalue) {
acc: Record<string, string>acc[const key: stringkey] = const value: stringvalue
}
return acc: Record<string, string>acc
}, {} as 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>)
)
}