Schema.decodeTo<
Schema.Boolean,
Schema.Literals<
readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]
>,
never,
never
>Schema for boolean values encoded as strings.
When to use
Use when you need the reusable boolean schema value for Config.schema with
custom paths.
Details
Accepted string values: true, false, yes, no, on, off, 1,
0, y, n (case-sensitive).
export const const Boolean: Schema.decodeTo<
Schema.Boolean,
Schema.Literals<
readonly [
"true",
"yes",
"on",
"1",
"y",
"false",
"no",
"off",
"0",
"n"
]
>,
never,
never
>
const Boolean: {
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
check: (checks_0: SchemaAST.Check<boolean>, ...checks: Array<SchemaAST.Check<boolean>>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
rebuild: (ast: SchemaAST.Boolean) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y', 'false', 'no', 'off', '0', 'n']>, never, never>;
make: (input: boolean, options?: MakeOptions) => boolean;
makeOption: (input: boolean, options?: MakeOptions) => Option_.Option<boolean>;
makeEffect: (input: boolean, options?: MakeOptions) => Effect.Effect<boolean, SchemaError, never>;
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; <…;
}
Schema for boolean values encoded as strings.
When to use
Use when you need the reusable boolean schema value for Config.schema with
custom paths.
Details
Accepted string values: true, false, yes, no, on, off, 1,
0, y, n (case-sensitive).
Boolean = import SchemaSchema.function Literals<
L extends ReadonlyArray<SchemaAST.LiteralValue>
>(literals: L): Literals<L>
Creates a union schema from an array of literal values.
Example (Defining status codes)
import { Schema } from "effect"
const schema = Schema.Literals(["active", "inactive", "pending"])
// accepts "active", "inactive", or "pending"
Literals([...const TrueValues: Schema.Literals<
readonly ["true", "yes", "on", "1", "y"]
>
const TrueValues: {
literals: L;
members: { readonly [K in keyof L]: Literal<L[K]>; };
mapMembers: (f: (members: readonly [Schema.Literal<'true'>, Schema.Literal<'yes'>, Schema.Literal<'on'>, Schema.Literal<'1'>, Schema.Literal<'y'>]) => To) => Schema.Union<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
pick: (literals: L2) => Schema.Literals<L2>;
transform: (to: L2) => Schema.Union<readonly [Schema.decodeTo<Schema.Literal<L2['0']>, Schema.Literal<'true'>, never, never>, Schema.decodeTo<Schema.Literal<L2['1']>, Schema.Literal<'yes'>, never, never>, Schema.decodeTo<Schema.Literal<L2['2']>, Sche…;
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<'1' | 'true' | 'yes' | 'on' | 'y', readonly []>) => Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y']>;
annotateKey: (annotations: Schema.Annotations.Key<'1' | 'true' | 'yes' | 'on' | 'y'>) => Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y']>;
check: (checks_0: SchemaAST.Check<'1' | 'true' | 'yes' | 'on' | 'y'>, ...checks: Array<SchemaAST.Check<'1' | 'true' | 'yes' | 'on' | 'y'>>) => Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y']>;
rebuild: (ast: SchemaAST.Union<SchemaAST.Literal>) => Schema.Literals<readonly ['true', 'yes', 'on', '1', 'y']>;
make: (input: '1' | 'true' | 'yes' | 'on' | 'y', options?: MakeOptions) => '1' | 'true' | 'yes' | 'on' | 'y';
makeOption: (input: '1' | 'true' | 'yes' | 'on' | 'y', options?: MakeOptions) => Option_.Option<'1' | 'true' | 'yes' | 'on' | 'y'>;
makeEffect: (input: '1' | 'true' | 'yes' | 'on' | 'y', options?: MakeOptions) => Effect.Effect<'1' | 'true' | 'yes' | 'on' | 'y', SchemaError, never>;
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; <…;
}
TrueValues.Literals<readonly ["true", "yes", "on", "1", "y"]>.literals: readonly ["true", "yes", "on", "1", "y"](property) Literals<readonly ["true", "yes", "on", "1", "y"]>.literals: {
0: 'true';
1: 'yes';
2: 'on';
3: '1';
4: 'y';
length: 5;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<'1' | 'true' | 'yes' | 'on' | 'y'>>): Array<'1' | 'true' | 'yes' | 'on' | 'y'>; (...items: Array<'1' | 'true' | 'yes' | 'on' | 'y' | ConcatArray<'1' | 'true' | 'yes' | 'on' | 'y'>>): Array<'1' | 'true' | 'yes…;
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<'1' | 'true' | 'yes' | 'on' | 'y'>;
indexOf: (searchElement: '1' | 'true' | 'yes' | 'on' | 'y', fromIndex?: number) => number;
lastIndexOf: (searchElement: '1' | 'true' | 'yes' | 'on' | 'y', fromIndex?: number) => number;
every: { (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', in…;
some: (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => void, thisArg?: any) => void;
map: (callbackfn: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => value is S, thisArg?: any): Array<S>; (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number,…;
reduce: { (callbackfn: (previousValue: '1' | 'true' | 'yes' | 'on' | 'y', currentValue: '1' | 'true' | 'yes' | 'on' | 'y', currentIndex: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => '1' | 'true' | 'yes' | 'on' | 'y'): '1' | …;
reduceRight: { (callbackfn: (previousValue: '1' | 'true' | 'yes' | 'on' | 'y', currentValue: '1' | 'true' | 'yes' | 'on' | 'y', currentIndex: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => '1' | 'true' | 'yes' | 'on' | 'y'): '1' | …;
find: { (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, obj: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => value is S, thisArg?: any): S | undefined; (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: numb…;
findIndex: (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, obj: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, '1' | 'true' | 'yes' | 'on' | 'y']>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<'1' | 'true' | 'yes' | 'on' | 'y'>;
includes: (searchElement: '1' | 'true' | 'yes' | 'on' | 'y', fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: Array<'1' | 'true' | 'yes' | 'on' | 'y'>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => '1' | 'true' | 'yes' | 'on' | 'y' | undefined;
findLast: { (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => value is S, thisArg?: any): S | undefined; (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: nu…;
findLastIndex: (predicate: (value: '1' | 'true' | 'yes' | 'on' | 'y', index: number, array: ReadonlyArray<'1' | 'true' | 'yes' | 'on' | 'y'>) => unknown, thisArg?: any) => number;
toReversed: () => Array<'1' | 'true' | 'yes' | 'on' | 'y'>;
toSorted: (compareFn?: ((a: '1' | 'true' | 'yes' | 'on' | 'y', b: '1' | 'true' | 'yes' | 'on' | 'y') => number) | undefined) => Array<'1' | 'true' | 'yes' | 'on' | 'y'>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<'1' | 'true' | 'yes' | 'on' | 'y'>): Array<'1' | 'true' | 'yes' | 'on' | 'y'>; (start: number, deleteCount?: number): Array<'1' | 'true' | 'yes' | 'on' | 'y'> };
with: (index: number, value: '1' | 'true' | 'yes' | 'on' | 'y') => Array<'1' | 'true' | 'yes' | 'on' | 'y'>;
}
literals, ...const FalseValues: Schema.Literals<
readonly ["false", "no", "off", "0", "n"]
>
const FalseValues: {
literals: L;
members: { readonly [K in keyof L]: Literal<L[K]>; };
mapMembers: (f: (members: readonly [Schema.Literal<'false'>, Schema.Literal<'no'>, Schema.Literal<'off'>, Schema.Literal<'0'>, Schema.Literal<'n'>]) => To) => Schema.Union<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
pick: (literals: L2) => Schema.Literals<L2>;
transform: (to: L2) => Schema.Union<readonly [Schema.decodeTo<Schema.Literal<L2['0']>, Schema.Literal<'false'>, never, never>, Schema.decodeTo<Schema.Literal<L2['1']>, Schema.Literal<'no'>, never, never>, Schema.decodeTo<Schema.Literal<L2['2']>, Sche…;
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<'0' | 'false' | 'no' | 'off' | 'n', readonly []>) => Schema.Literals<readonly ['false', 'no', 'off', '0', 'n']>;
annotateKey: (annotations: Schema.Annotations.Key<'0' | 'false' | 'no' | 'off' | 'n'>) => Schema.Literals<readonly ['false', 'no', 'off', '0', 'n']>;
check: (checks_0: SchemaAST.Check<'0' | 'false' | 'no' | 'off' | 'n'>, ...checks: Array<SchemaAST.Check<'0' | 'false' | 'no' | 'off' | 'n'>>) => Schema.Literals<readonly ['false', 'no', 'off', '0', 'n']>;
rebuild: (ast: SchemaAST.Union<SchemaAST.Literal>) => Schema.Literals<readonly ['false', 'no', 'off', '0', 'n']>;
make: (input: '0' | 'false' | 'no' | 'off' | 'n', options?: MakeOptions) => '0' | 'false' | 'no' | 'off' | 'n';
makeOption: (input: '0' | 'false' | 'no' | 'off' | 'n', options?: MakeOptions) => Option_.Option<'0' | 'false' | 'no' | 'off' | 'n'>;
makeEffect: (input: '0' | 'false' | 'no' | 'off' | 'n', options?: MakeOptions) => Effect.Effect<'0' | 'false' | 'no' | 'off' | 'n', SchemaError, never>;
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; <…;
}
FalseValues.Literals<readonly ["false", "no", "off", "0", "n"]>.literals: readonly ["false", "no", "off", "0", "n"](property) Literals<readonly ["false", "no", "off", "0", "n"]>.literals: {
0: 'false';
1: 'no';
2: 'off';
3: '0';
4: 'n';
length: 5;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<'0' | 'false' | 'no' | 'off' | 'n'>>): Array<'0' | 'false' | 'no' | 'off' | 'n'>; (...items: Array<'0' | 'false' | 'no' | 'off' | 'n' | ConcatArray<'0' | 'false' | 'no' | 'off' | 'n'>>): Array<'0' | 'false' |…;
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<'0' | 'false' | 'no' | 'off' | 'n'>;
indexOf: (searchElement: '0' | 'false' | 'no' | 'off' | 'n', fromIndex?: number) => number;
lastIndexOf: (searchElement: '0' | 'false' | 'no' | 'off' | 'n', fromIndex?: number) => number;
every: { (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n',…;
some: (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => void, thisArg?: any) => void;
map: (callbackfn: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => value is S, thisArg?: any): Array<S>; (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: numb…;
reduce: { (callbackfn: (previousValue: '0' | 'false' | 'no' | 'off' | 'n', currentValue: '0' | 'false' | 'no' | 'off' | 'n', currentIndex: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => '0' | 'false' | 'no' | 'off' | 'n'): '0…;
reduceRight: { (callbackfn: (previousValue: '0' | 'false' | 'no' | 'off' | 'n', currentValue: '0' | 'false' | 'no' | 'off' | 'n', currentIndex: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => '0' | 'false' | 'no' | 'off' | 'n'): '0…;
find: { (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, obj: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => value is S, thisArg?: any): S | undefined; (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: n…;
findIndex: (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, obj: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, '0' | 'false' | 'no' | 'off' | 'n']>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<'0' | 'false' | 'no' | 'off' | 'n'>;
includes: (searchElement: '0' | 'false' | 'no' | 'off' | 'n', fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: Array<'0' | 'false' | 'no' | 'off' | 'n'>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => '0' | 'false' | 'no' | 'off' | 'n' | undefined;
findLast: { (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => value is S, thisArg?: any): S | undefined; (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index:…;
findLastIndex: (predicate: (value: '0' | 'false' | 'no' | 'off' | 'n', index: number, array: ReadonlyArray<'0' | 'false' | 'no' | 'off' | 'n'>) => unknown, thisArg?: any) => number;
toReversed: () => Array<'0' | 'false' | 'no' | 'off' | 'n'>;
toSorted: (compareFn?: ((a: '0' | 'false' | 'no' | 'off' | 'n', b: '0' | 'false' | 'no' | 'off' | 'n') => number) | undefined) => Array<'0' | 'false' | 'no' | 'off' | 'n'>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<'0' | 'false' | 'no' | 'off' | 'n'>): Array<'0' | 'false' | 'no' | 'off' | 'n'>; (start: number, deleteCount?: number): Array<'0' | 'false' | 'no' | 'off' | 'n'> };
with: (index: number, value: '0' | 'false' | 'no' | 'off' | 'n') => Array<'0' | 'false' | 'no' | 'off' | 'n'>;
}
literals]).Pipeable.pipe<Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>, Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>, never, never>>(this: Schema.Literals<readonly ["true", ... 8 more ..., "n"]>, ab: (_: Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>) => Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>, never, never>): Schema.decodeTo<...> (+21 overloads)pipe(
import SchemaSchema.function decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>, never, never>(to: Schema.Boolean, transformation: {
readonly decode: SchemaGetter.Getter<boolean, "0" | "1" | "true" | "yes" | "on" | "y" | "false" | "no" | "off" | "n", never>;
readonly encode: SchemaGetter.Getter<"0" | "1" | "true" | "yes" | "on" | "y" | "false" | "no" | "off" | "n", boolean, never>;
}): (from: Schema.Literals<readonly ["true", "yes", "on", "1", "y", "false", "no", "off", "0", "n"]>) => Schema.decodeTo<...> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
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))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(
import SchemaSchema.const Boolean: Booleanconst Boolean: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.Boolean;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.Boolean;
check: (checks_0: SchemaAST.Check<boolean>, ...checks: Array<SchemaAST.Check<boolean>>) => Schema.Boolean;
rebuild: (ast: SchemaAST.Boolean) => Schema.Boolean;
make: (input: boolean, options?: MakeOptions) => boolean;
makeOption: (input: boolean, options?: MakeOptions) => Option_.Option<boolean>;
makeEffect: (input: boolean, options?: MakeOptions) => Effect.Effect<boolean, SchemaError, never>;
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; <…;
}
Type-level representation of
Boolean
.
Schema for boolean values. Validates that the input is typeof "boolean".
When to use
Use to validate values that are already JavaScript booleans.
Boolean,
import SchemaTransformationSchemaTransformation.function transform<T, E>(options: {
readonly decode: (input: E) => T
readonly encode: (input: T) => E
}): Transformation<T, E>
Creates a Transformation from pure (sync, infallible) decode and encode
functions.
When to use
Use when you need an infallible schema transformation that does not require
Effect services.
Details
- Each function receives the input and returns the output directly.
- Skips
None inputs (missing keys) — functions are only called on present values.
- Does not allocate Effects internally; uses optimized sync path.
Example (Converting between cents and dollars)
import { Schema, SchemaTransformation } from "effect"
const CentsFromDollars = Schema.Number.pipe(
Schema.decodeTo(
Schema.Number,
SchemaTransformation.transform({
decode: (dollars) => dollars * 100,
encode: (cents) => cents / 100
})
)
)
transform({
decode: (
input:
| "0"
| "1"
| "true"
| "yes"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
) => boolean
decode: (value: | "0"
| "1"
| "true"
| "yes"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
value) => value: | "0"
| "1"
| "true"
| "yes"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
value === "true" || value: | "0"
| "1"
| "yes"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
value === "yes" || value: | "0"
| "1"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
value === "on" || value: | "0"
| "1"
| "y"
| "false"
| "no"
| "off"
| "n"
value === "1" || value: "0" | "y" | "false" | "no" | "off" | "n"value === "y",
encode: (
input: boolean
) =>
| "0"
| "1"
| "true"
| "yes"
| "on"
| "y"
| "false"
| "no"
| "off"
| "n"
encode: (value: booleanvalue) => value: booleanvalue ? "true" : "false"
})
)
)