<S extends Schema.Constraint>(schema: S): <
IE = never,
Done = unknown
>() => Channel.Channel<
Arr.NonEmptyReadonlyArray<S["Encoded"]>,
IE | Schema.SchemaError,
Done,
Arr.NonEmptyReadonlyArray<S["Type"]>,
IE,
Done,
S["EncodingServices"]
>Creates a channel that encodes non-empty chunks of schema values into the schema's encoded representation.
When to use
Use to encode typed channel input into the schema's encoded representation before passing chunks to an encoded downstream boundary.
Details
Encoding failures are emitted as SchemaError, and any encoding services
required by the schema become channel requirements.
export const const encode: <
S extends Schema.Constraint
>(
schema: S
) => <
IE = never,
Done = unknown
>() => Channel.Channel<
Arr.NonEmptyReadonlyArray<S["Encoded"]>,
IE | Schema.SchemaError,
Done,
Arr.NonEmptyReadonlyArray<S["Type"]>,
IE,
Done,
S["EncodingServices"]
>
Creates a channel that encodes non-empty chunks of schema values into the
schema's encoded representation.
When to use
Use to encode typed channel input into the schema's encoded representation
before passing chunks to an encoded downstream boundary.
Details
Encoding failures are emitted as SchemaError, and any encoding services
required by the schema become channel requirements.
encode = <function (type parameter) S in <S extends Schema.Constraint>(schema: S): <IE = never, Done = unknown>() => Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>S extends import SchemaSchema.Constraint>(
schema: S extends Schema.Constraintschema: function (type parameter) S in <S extends Schema.Constraint>(schema: S): <IE = never, Done = unknown>() => Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>S
) =>
<function (type parameter) IE in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>IE = never, function (type parameter) Done in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>Done = unknown>(): import ChannelChannel.type Channel.Channel = /*unresolved*/ anyChannel<
import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) S in <S extends Schema.Constraint>(schema: S): <IE = never, Done = unknown>() => Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>S["Encoded"]>,
function (type parameter) IE in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>IE | import SchemaSchema.class SchemaError
export SchemaError
class SchemaError {
message: string;
toString: () => string;
name: string;
stack: string;
cause: unknown;
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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
SchemaIssue.Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError,
function (type parameter) Done in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>Done,
import ArrArr.type Arr.NonEmptyReadonlyArray = /*unresolved*/ anyNonEmptyReadonlyArray<function (type parameter) S in <S extends Schema.Constraint>(schema: S): <IE = never, Done = unknown>() => Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>S["Type"]>,
function (type parameter) IE in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>IE,
function (type parameter) Done in <IE = never, Done = unknown>(): Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>Done,
function (type parameter) S in <S extends Schema.Constraint>(schema: S): <IE = never, Done = unknown>() => Channel.Channel<Arr.NonEmptyReadonlyArray<S["Encoded"]>, IE | Schema.SchemaError, Done, Arr.NonEmptyReadonlyArray<S["Type"]>, IE, Done, S["EncodingServices"]>S["EncodingServices"]
> => {
const const encode: (
input: readonly [S["Type"], ...S["Type"][]],
options?: SchemaAST.ParseOptions
) => Effect.Effect<
readonly [S["Encoded"], ...S["Encoded"][]],
SchemaError,
S["EncodingServices"]
>
encode = import SchemaSchema.const encodeEffect: <
S extends Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Type"],
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Encoded"],
SchemaError,
S["EncodingServices"]
>
Encodes a typed input (the schema's Type) against a schema, returning an
Effect that succeeds with the encoded value or fails with a
When to use
Use when you need to encode input already typed as the schema's Type in
an Effect whose failure channel is SchemaError.
Details
For unknown input use
encodeUnknownEffect
.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
encodeEffect(import SchemaSchema.const NonEmptyArray: NonEmptyArrayLambda
;<S>(self: S) => Schema.NonEmptyArray<S>
Type-level representation returned by
NonEmptyArray
.
Defines a non-empty ReadonlyArray schema — at least one element required.
Type is readonly [T, ...T[]].
Example (Defining a non-empty array of numbers)
import { Schema } from "effect"
const schema = Schema.NonEmptyArray(Schema.Number)
Schema.decodeUnknownSync(schema)([1, 2, 3]) // ok
Schema.decodeUnknownSync(schema)([]) // throws
NonEmptyArray(schema: S extends Schema.Constraintschema))
return import ChannelChannel.fromTransform((upstream: Pull<
readonly [S["Type"], ...S["Type"][]],
IE,
Done,
never
>
(parameter) upstream: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
upstream, _scope: Scope(parameter) _scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
_scope) => import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(upstream: Pull<
readonly [S["Type"], ...S["Type"][]],
IE,
Done,
never
>
(parameter) upstream: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
upstream, (chunk: unknown(parameter) chunk: {
0: S['Type'];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<S['Type']>>): Array<S['Type']>; (...items: Array<S['Type'] | ConcatArray<S['Type']>>): Array<S['Type']> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<S['Type']>;
indexOf: (searchElement: S['Type'], fromIndex?: number) => number;
lastIndexOf: (searchElement: S['Type'], fromIndex?: number) => number;
every: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any)…;
some: (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => void, thisArg?: any) => void;
map: (callbackfn: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): Array<S>; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): Array<S['T…;
reduce: { (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, array: ReadonlyArray<S['Type']>) => S['Type']): S['Type']; (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, arra…;
reduceRight: { (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, array: ReadonlyArray<S['Type']>) => S['Type']): S['Type']; (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, arra…;
find: { (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): S | undefined; (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): S['Type']…;
findIndex: (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, S['Type']]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<S['Type']>;
includes: (searchElement: S['Type'], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: S['Type'], index: number, array: Array<S['Type']>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => S['Type'] | undefined;
findLast: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): S | undefined; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): S['Ty…;
findLastIndex: (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => number;
toReversed: () => Array<S['Type']>;
toSorted: (compareFn?: ((a: S['Type'], b: S['Type']) => number) | undefined) => Array<S['Type']>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<S['Type']>): Array<S['Type']>; (start: number, deleteCount?: number): Array<S['Type']> };
with: (index: number, value: S['Type']) => Array<S['Type']>;
}
chunk) => const encode: (
input: readonly [S["Type"], ...S["Type"][]],
options?: SchemaAST.ParseOptions
) => Effect.Effect<
readonly [S["Encoded"], ...S["Encoded"][]],
SchemaError,
S["EncodingServices"]
>
encode(chunk: unknown(parameter) chunk: {
0: S['Type'];
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<S['Type']>>): Array<S['Type']>; (...items: Array<S['Type'] | ConcatArray<S['Type']>>): Array<S['Type']> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<S['Type']>;
indexOf: (searchElement: S['Type'], fromIndex?: number) => number;
lastIndexOf: (searchElement: S['Type'], fromIndex?: number) => number;
every: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any)…;
some: (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => void, thisArg?: any) => void;
map: (callbackfn: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): Array<S>; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): Array<S['T…;
reduce: { (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, array: ReadonlyArray<S['Type']>) => S['Type']): S['Type']; (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, arra…;
reduceRight: { (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, array: ReadonlyArray<S['Type']>) => S['Type']): S['Type']; (callbackfn: (previousValue: S['Type'], currentValue: S['Type'], currentIndex: number, arra…;
find: { (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): S | undefined; (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): S['Type']…;
findIndex: (predicate: (value: S['Type'], index: number, obj: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, S['Type']]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<S['Type']>;
includes: (searchElement: S['Type'], fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: S['Type'], index: number, array: Array<S['Type']>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => S['Type'] | undefined;
findLast: { (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => value is S, thisArg?: any): S | undefined; (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any): S['Ty…;
findLastIndex: (predicate: (value: S['Type'], index: number, array: ReadonlyArray<S['Type']>) => unknown, thisArg?: any) => number;
toReversed: () => Array<S['Type']>;
toSorted: (compareFn?: ((a: S['Type'], b: S['Type']) => number) | undefined) => Array<S['Type']>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<S['Type']>): Array<S['Type']>; (start: number, deleteCount?: number): Array<S['Type']> };
with: (index: number, value: S['Type']) => Array<S['Type']>;
}
chunk))))
}