(): Getter<FormData, unknown>Encodes a nested object into a FormData instance using bracket-path notation.
When to use
Use when you need a schema getter to serialize structured data to FormData
for HTTP requests.
Details
The getter is pure and never fails. It flattens nested objects or arrays into
bracket-path keys such as user[name] and items[0]. Non-object inputs
produce an empty FormData.
Example (Encoding to FormData)
import { SchemaGetter } from "effect"
const encode = SchemaGetter.encodeFormData()
// Getter<FormData, unknown>export function function encodeFormData(): Getter<
FormData,
unknown
>
Encodes a nested object into a FormData instance using bracket-path notation.
When to use
Use when you need a schema getter to serialize structured data to FormData
for HTTP requests.
Details
The getter is pure and never fails. It flattens nested objects or arrays into
bracket-path keys such as user[name] and items[0]. Non-object inputs
produce an empty FormData.
Example (Encoding to FormData)
import { SchemaGetter } from "effect"
const encode = SchemaGetter.encodeFormData()
// Getter<FormData, unknown>
encodeFormData(): 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<FormData, unknown> {
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: unknowninput) => {
const const out: FormDataout = new var FormData: new (
form?: HTMLFormElement,
submitter?: HTMLElement | null
) => FormData
The FormData interface provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using the Window/fetch, XMLHttpRequest.send() or navigator.sendBeacon() methods.
FormData()
if (typeof input: unknowninput === "object" && input: object | nullinput !== null) {
const const entries: [
bracketPath: string,
value: string | Blob
][]
entries = const collectFormDataEntries: (
input: object
) => [bracketPath: string, value: string | Blob][]
collectFormDataEntries(input: objectinput)
const entries: [
bracketPath: string,
value: string | Blob
][]
entries.Array<[bracketPath: string, value: string | Blob]>.forEach(callbackfn: (value: [bracketPath: string, value: string | Blob], index: number, array: [bracketPath: string, value: string | Blob][]) => void, thisArg?: any): voidPerforms the specified action for each element in an array.
forEach(([key: stringkey, value: string | Blobvalue]) => {
const out: FormDataout.FormData.append(name: string, value: string | Blob): void (+2 overloads)The append() method of the FormData interface appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist.
append(key: stringkey, value: string | Blobvalue)
})
}
return const out: FormDataout
})
}