<E extends string | number | Date>(): Getter<Date, E>Coerces a value to a Date using new Date(input).
When to use
Use when you need a schema getter to coerce a present string, number, or existing date object into a new date object.
Details
- Delegates to
new globalThis.Date(input). - Does not validate the result — may produce an invalid Date.
Example (Coercing to a Date)
import { SchemaGetter } from "effect"
const toDate = SchemaGetter.Date<string>()
// Getter<Date, string>export function function Date<
E extends string | number | Date
>(): Getter<Date, E>
Coerces a value to a Date using new Date(input).
When to use
Use when you need a schema getter to coerce a present string, number, or
existing date object into a new date object.
Details
- Delegates to
new globalThis.Date(input).
- Does not validate the result — may produce an invalid Date.
Example (Coercing to a Date)
import { SchemaGetter } from "effect"
const toDate = SchemaGetter.Date<string>()
// Getter<Date, string>
Date<function (type parameter) E in Date<E extends string | number | Date>(): Getter<Date, E>E extends string | number | Date>(): 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<Date, function (type parameter) E in Date<E extends string | number | Date>(): Getter<Date, E>E> {
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((u: E extends string | number | Dateu) => new module globalThisglobalThis.var Date: DateConstructor
new (value: number | string | Date) => Date (+4 overloads)
Date(u: string | number | Dateu))
}