Chunk<Value>Schema for chunks whose values conform to the provided element schema.
export interface interface Chunk<Value extends Constraint>Schema for chunks whose values conform to the provided element schema.
Type-level representation returned by
Chunk
.
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>Value extends Constraint> extends
interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<
import Chunk_Chunk_.interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>Value["Type"]>,
import Chunk_Chunk_.interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>Value["Encoded"]>,
readonly [function (type parameter) Value in Chunk<Value extends Constraint>Value],
type ChunkIso<Value extends Constraint> =
readonly Value["Iso"][]
Iso representation used for Chunk schemas: an array of element values using
the element schema's Iso type.
When to use
Use when annotating type-level helpers that work with the readonly-array ISO
shape of a Chunk schema.
ChunkIso<function (type parameter) Value in Chunk<Value extends Constraint>Value>
>
{
readonly "Rebuild": interface Chunk<Value extends Constraint>Schema for chunks whose values conform to the provided element schema.
Type-level representation returned by
Chunk
.
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>Value>
readonly Chunk<Value extends Constraint>.value: Value extends Constraintvalue: function (type parameter) Value in Chunk<Value extends Constraint>Value
}
/**
* Iso representation used for `Chunk` schemas: an array of element values using
* the element schema's `Iso` type.
*
* **When to use**
*
* Use when annotating type-level helpers that work with the readonly-array ISO
* shape of a `Chunk` schema.
*
* @see {@link Chunk} for the schema interface and constructor that use this ISO representation
*
* @category Chunk
* @since 4.0.0
*/
export type type ChunkIso<Value extends Constraint> =
readonly Value["Iso"][]
Iso representation used for Chunk schemas: an array of element values using
the element schema's Iso type.
When to use
Use when annotating type-level helpers that work with the readonly-array ISO
shape of a Chunk schema.
ChunkIso<function (type parameter) Value in type ChunkIso<Value extends Constraint>Value extends Constraint> = interface ReadonlyArray<T>ReadonlyArray<function (type parameter) Value in type ChunkIso<Value extends Constraint>Value["Iso"]>
/**
* Schema for chunks whose values conform to the provided element schema.
*
* @category Chunk
* @since 3.10.0
*/
export function function Chunk<Value extends Constraint>(
value: Value
): Chunk<Value>
Schema for chunks whose values conform to the provided element schema.
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value extends Constraint>(value: Value extends Constraintvalue: function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value): interface Chunk<Value extends Constraint>Schema for chunks whose values conform to the provided element schema.
Type-level representation returned by
Chunk
.
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value> {
const const schema: declareConstructor<
Chunk_.Chunk<Value["Type"]>,
Chunk_.Chunk<Value["Encoded"]>,
readonly [Value],
ChunkIso<Value>
>
const schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Chunk_.Chunk<Value['Type']>, readonly [Value]>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
annotateKey: (annotations: Annotations.Key<Chunk_.Chunk<Value['Type']>>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
check: (checks_0: SchemaAST.Check<Chunk_.Chunk<Value['Type']>>, ...checks: Array<SchemaAST.Check<Chunk_.Chunk<Value['Type']>>>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
make: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Chunk_.Chunk<Value['Type']>;
makeOption: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Option_.Option<Chunk_.Chunk<Value['Type']>>;
makeEffect: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Effect.Effect<Chunk_.Chunk<Value['Type']>, 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 = function declareConstructor<
T,
E = T,
Iso = T
>(): <
TypeParameters extends ReadonlyArray<Constraint>
>(
typeParameters: TypeParameters,
run: (typeParameters: {
readonly [K in keyof TypeParameters]: Codec<
TypeParameters[K]["Type"],
TypeParameters[K]["Encoded"]
>
}) => (
u: unknown,
self: SchemaAST.Declaration,
options: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue>,
annotations?: Annotations.Declaration<
T,
TypeParameters
>
) => declareConstructor<T, E, TypeParameters, Iso>
Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
declareConstructor<
import Chunk_Chunk_.interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value["Type"]>,
import Chunk_Chunk_.interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value["Encoded"]>,
type ChunkIso<Value extends Constraint> =
readonly Value["Iso"][]
Iso representation used for Chunk schemas: an array of element values using
the element schema's Iso type.
When to use
Use when annotating type-level helpers that work with the readonly-array ISO
shape of a Chunk schema.
ChunkIso<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value>
>()(
[value: Value extends Constraintvalue],
([value: Codec<
Value["Type"],
Value["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Value['Type'], any>) => Codec<Value['Type'], Value['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<Value['Type']>) => Codec<Value['Type'], Value['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<Value['Type']>, ...checks: Array<SchemaAST.Check<Value['Type']>>) => Codec<Value['Type'], Value['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<Value['Type'], Value['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => Value['Type'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<Value['Type']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<Value['Type'], 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; <…;
}
value]) => {
const const values: $Array<
Codec<
Value["Type"],
Value["Encoded"],
never,
never
>
>
const values: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<ReadonlyArray<Value['Type']>, readonly []>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
annotateKey: (annotations: Annotations.Key<ReadonlyArray<Value['Type']>>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<Value['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<Value['Type']>>>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
rebuild: (ast: SchemaAST.Arrays) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
make: (input: ReadonlyArray<unknown>, options?: MakeOptions) => ReadonlyArray<Value['Type']>;
makeOption: (input: ReadonlyArray<unknown>, options?: MakeOptions) => Option_.Option<ReadonlyArray<Value['Type']>>;
makeEffect: (input: ReadonlyArray<unknown>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<Value['Type']>, 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; <…;
}
values = const ArraySchema: ArrayLambda
<Codec<Value["Type"], Value["Encoded"], never, never>>(self: Codec<Value["Type"], Value["Encoded"], never, never>) => $Array<Codec<Value["Type"], Value["Encoded"], never, never>>
ArraySchema(value: Codec<
Value["Type"],
Value["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Value['Type'], any>) => Codec<Value['Type'], Value['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<Value['Type']>) => Codec<Value['Type'], Value['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<Value['Type']>, ...checks: Array<SchemaAST.Check<Value['Type']>>) => Codec<Value['Type'], Value['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<Value['Type'], Value['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => Value['Type'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<Value['Type']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<Value['Type'], 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; <…;
}
value)
return (input: unknowninput, ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options) => {
if (import Chunk_Chunk_.const isChunk: {
<A>(u: Iterable<A>): u is Chunk<A>
(u: unknown): u is Chunk<unknown>
}
isChunk(input: unknowninput)) {
return import EffectEffect.const mapBothEager: {
<E, E2, A, A2>(options: {
readonly onFailure: (e: E) => E2
readonly onSuccess: (a: A) => A2
}): <R>(
self: Effect<A, E, R>
) => Effect<A2, E2, R>
<A, E, R, E2, A2>(
self: Effect<A, E, R>,
options: {
readonly onFailure: (e: E) => E2
readonly onSuccess: (a: A) => A2
}
): Effect<A2, E2, R>
}
mapBothEager(
import SchemaParserSchemaParser.function decodeUnknownEffect<
S extends Schema.Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
S["DecodingServices"]
>
Creates an effectful decoder for unknown input.
When to use
Use when you need to decode untyped boundary input in an Effect whose
failure channel is SchemaIssue.Issue, while preserving transformations
and service requirements.
Details
The returned function succeeds with the schema's decoded Type or fails with a
SchemaIssue.Issue. Decoding service requirements are preserved in the returned
Effect. Parse options may be provided when creating the decoder and overridden
when applying it.
decodeUnknownEffect(const values: $Array<
Codec<
Value["Type"],
Value["Encoded"],
never,
never
>
>
const values: {
Type: ReadonlyArray<S["Type"]>;
Encoded: ReadonlyArray<S["Encoded"]>;
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: ReadonlyArray<S["Iso"]>;
value: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<ReadonlyArray<Value['Type']>, readonly []>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
annotateKey: (annotations: Annotations.Key<ReadonlyArray<Value['Type']>>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
check: (checks_0: SchemaAST.Check<ReadonlyArray<Value['Type']>>, ...checks: Array<SchemaAST.Check<ReadonlyArray<Value['Type']>>>) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
rebuild: (ast: SchemaAST.Arrays) => $Array<Codec<Value['Type'], Value['Encoded'], never, never>>;
make: (input: ReadonlyArray<unknown>, options?: MakeOptions) => ReadonlyArray<Value['Type']>;
makeOption: (input: ReadonlyArray<unknown>, options?: MakeOptions) => Option_.Option<ReadonlyArray<Value['Type']>>;
makeEffect: (input: ReadonlyArray<unknown>, options?: MakeOptions) => Effect.Effect<ReadonlyArray<Value['Type']>, 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; <…;
}
values)(import ArrArr.const fromIterable: <unknown>(
collection: Iterable<unknown>
) => unknown[]
Converts an Iterable to an Array.
When to use
Use to convert any Iterable (Set, Generator, etc.) into an array.
Details
If the input is already an array, this returns it by reference without
copying. Otherwise, it creates a new array from the iterable. Use copy if
you need a fresh array even when the input is already an array.
Example (Converting a Set to an array)
import { Array } from "effect"
const result = Array.fromIterable(new Set([1, 2, 3]))
console.log(result) // [1, 2, 3]
fromIterable(input: Chunk_.Chunk<unknown>(parameter) input: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
input), options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options),
{
onSuccess: <A>(self: Iterable<A>) => Chunk<A>onSuccess: import Chunk_Chunk_.const fromIterable: <A>(
self: Iterable<A>
) => Chunk<A>
Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
fromIterable,
onFailure: (
e: SchemaIssue.Issue
) => SchemaIssue.Composite
onFailure: (issue: SchemaIssue.Issueissue) =>
new import SchemaIssueSchemaIssue.constructor Composite(ast: SchemaAST.AST, actual: Option_.Option<unknown>, issues: readonly [SchemaIssue.Issue, ...Array<SchemaIssue.Issue>]): SchemaIssue.CompositeRepresents a schema issue that groups multiple child issues under a single schema node.
When to use
Use when you need to walk the issue tree for struct/tuple schemas that collect
all field errors rather than failing on the first.
Details
issues is a non-empty readonly array (at least one child).
actual is Option.some(value) when the input was present, or
Option.none() when absent.
- Formatters flatten
Composite by recursing into each child.
Composite(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, import Option_Option_.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(input: Chunk_.Chunk<unknown>(parameter) input: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
input), [new import SchemaIssueSchemaIssue.constructor Pointer(path: ReadonlyArray<PropertyKey>, issue: SchemaIssue.Issue): SchemaIssue.PointerWraps an inner
Issue
with a property-key path, indicating where in
a nested structure the error occurred.
When to use
Use when you need to walk the issue tree to accumulate path segments for error
reporting.
Details
path is an array of property keys (strings, numbers, or symbols).
- Has no
actual value —
getActual
returns Option.none().
- Formatters concatenate nested
Pointer paths into a single path like
["a"]["b"][0].
Pointer(["values"], issue: SchemaIssue.Issueissue)])
}
)
}
return import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(new import SchemaIssueSchemaIssue.constructor InvalidType(ast: SchemaAST.AST, actual: Option_.Option<unknown>): SchemaIssue.InvalidTypeRepresents a schema issue produced when the runtime type of the input does not match the type
expected by the schema (e.g. got null when string was expected).
When to use
Use when you need to detect basic type mismatches, such as a wrong primitive
or null where an object was expected.
Details
ast is the schema node that expected a different type.
actual is Option.some(value) when the input was present, or
Option.none() when no value was provided.
- The default formatter renders this as
"Expected <type>, got <actual>".
Example (Formatting output)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.String)(42)
} catch (e) {
if (Schema.isSchemaError(e)) {
console.log(String(e.issue))
// "Expected string, got 42"
}
}
InvalidType(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, import Option_Option_.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(input: unknowninput)))
}
},
{
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "effect/Chunk"
},
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.Chunk(?)`,
type Type: stringType: `Chunk.Chunk<?>`
},
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "Chunk",
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.toCodec?: ((typeParameters: readonly [Codec<Value["Encoded"], Value["Encoded"], never, never>]) => SchemaAST.Link) | undefinedtoCodec: ([value: Codec<
Value["Encoded"],
Value["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Value['Encoded'], any>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<Value['Encoded']>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<Value['Encoded']>, ...checks: Array<SchemaAST.Check<Value['Encoded']>>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => Value['Encoded'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<Value['Encoded']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<Value['Encoded'], 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; <…;
}
value]) =>
function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<import Chunk_Chunk_.interface Chunk<out A>A Chunk is an immutable, ordered collection optimized for efficient concatenation and access patterns.
Example (Inspecting chunk values)
import { Chunk } from "effect"
const chunk: Chunk.Chunk<number> = Chunk.make(1, 2, 3)
console.log(chunk.length) // 3
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
A namespace containing utility types for Chunk operations.
Example (Working with Chunk utility types)
import type { Chunk } from "effect"
// Extract the element type from a Chunk
declare const chunk: Chunk.Chunk<string>
type ElementType = Chunk.Chunk.Infer<typeof chunk> // string
// Create a preserving non-emptiness
declare const nonEmptyChunk: Chunk.NonEmptyChunk<number>
type WithString = Chunk.Chunk.With<typeof nonEmptyChunk, string> // Chunk.NonEmptyChunk<string>
Chunk<function (type parameter) Value in Chunk<Value extends Constraint>(value: Value): Chunk<Value>Value["Encoded"]>>()(
const ArraySchema: ArrayLambda
<Codec<Value["Encoded"], Value["Encoded"], never, never>>(self: Codec<Value["Encoded"], Value["Encoded"], never, never>) => $Array<Codec<Value["Encoded"], Value["Encoded"], never, never>>
ArraySchema(value: Codec<
Value["Encoded"],
Value["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Value['Encoded'], any>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<Value['Encoded']>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<Value['Encoded']>, ...checks: Array<SchemaAST.Check<Value['Encoded']>>) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<Value['Encoded'], Value['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => Value['Encoded'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<Value['Encoded']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<Value['Encoded'], 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; <…;
}
value),
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: <A>(self: Iterable<A>) => Chunk<A>decode: import Chunk_Chunk_.const fromIterable: <A>(
self: Iterable<A>
) => Chunk<A>
Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
fromIterable,
encode: (
input: Chunk_.Chunk<Value["Encoded"]>
) => NoInfer<readonly Value["Encoded"][]>
encode: import ArrArr.const fromIterable: <A>(
collection: Iterable<A>
) => Array<A>
Converts an Iterable to an Array.
When to use
Use to convert any Iterable (Set, Generator, etc.) into an array.
Details
If the input is already an array, this returns it by reference without
copying. Otherwise, it creates a new array from the iterable. Use copy if
you need a fresh array even when the input is already an array.
Example (Converting a Set to an array)
import { Array } from "effect"
const result = Array.fromIterable(new Set([1, 2, 3]))
console.log(result) // [1, 2, 3]
fromIterable
})
),
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.toArbitrary?: Annotations.ToArbitrary.Declaration<Chunk_.Chunk<Value["Type"]>, readonly [Value]> | undefinedtoArbitrary: ([value: Annotations.ToArbitrary.TypeParameter<
Value["Type"]
>
(parameter) value: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
value]) => (fc: typeof FastCheckfc, ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx) =>
function collectionArbitrary<unknown, Chunk_.Chunk<unknown>>(fc: typeof FastCheck, ctx: Annotations.ToArbitrary.Context, item: FastCheck.Arbitrary<unknown>, terminalItem: FastCheck.Arbitrary<unknown> | undefined, fromIterable: (items: unknown[]) => Chunk_.Chunk<unknown>, comparator?: ((a: unknown, b: unknown) => boolean) | undefined): {
arbitrary: any;
terminal: any;
}
collectionArbitrary(fc: typeof FastCheckfc, ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx, value: Annotations.ToArbitrary.TypeParameter<
Value["Type"]
>
(parameter) value: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
value.Annotations.ToArbitrary.TypeParameter<T>.arbitrary: FastCheck.Arbitrary<T>arbitrary, value: Annotations.ToArbitrary.TypeParameter<
Value["Type"]
>
(parameter) value: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
value.Annotations.ToArbitrary.TypeParameter<T>.terminal: anyterminal, import Chunk_Chunk_.const fromIterable: <A>(
self: Iterable<A>
) => Chunk<A>
Creates a new Chunk from an iterable collection of values.
Example (Creating chunks from iterables)
import { Chunk } from "effect"
const chunk = Chunk.fromIterable([1, 2, 3])
console.log(Chunk.toArray(chunk)) // [1, 2, 3]
fromIterable),
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.toEquivalence?: Annotations.ToEquivalence.Declaration<Chunk_.Chunk<Value["Type"]>, readonly [Value]> | undefinedtoEquivalence: ([value: Equivalence.Equivalence<Value["Type"]>value]) => import Chunk_Chunk_.const makeEquivalence: <A>(
isEquivalent: Equivalence.Equivalence<A>
) => Equivalence.Equivalence<Chunk<A>>
Creates an Equivalence for chunks that compares chunk lengths and then
compares corresponding elements with the provided element equivalence.
Example (Comparing chunks for equivalence)
import { Chunk, Equivalence } from "effect"
const chunk1 = Chunk.make(1, 2, 3)
const chunk2 = Chunk.make(1, 2, 3)
const chunk3 = Chunk.make(1, 2, 4)
const eq = Chunk.makeEquivalence(Equivalence.strictEqual<number>())
console.log(eq(chunk1, chunk2)) // true
console.log(eq(chunk1, chunk3)) // false
makeEquivalence(value: Equivalence.Equivalence<Value["Type"]>value),
Annotations.Declaration<Chunk<Value["Type"]>, readonly [Value]>.toFormatter?: Annotations.ToFormatter.Declaration<Chunk_.Chunk<Value["Type"]>, readonly [Value]> | undefinedtoFormatter: ([value: Formatter<Value["Type"], string>value]) => (t: Chunk_.Chunk<Value["Type"]>(parameter) t: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
t) => {
const const size: numbersize = import Chunk_Chunk_.const size: <A>(self: Chunk<A>) => numberRetrieves the size of the chunk.
Example (Getting chunk size)
import { Chunk } from "effect"
const chunk = Chunk.make(1, 2, 3)
console.log(Chunk.size(chunk)) // 3
size(t: Chunk_.Chunk<Value["Type"]>(parameter) t: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
t)
if (const size: numbersize === 0) {
return "Chunk(0) {}"
}
const const values: string[]values = module globalThisglobalThis.var Array: ArrayConstructorArray.ArrayConstructor.from<Value["Type"]>(iterable: Iterable<Value["Type"]> | ArrayLike<Value["Type"]>): Value["Type"][] (+3 overloads)Creates an array from an iterable object.
from(t: Chunk_.Chunk<Value["Type"]>(parameter) t: {
length: number;
right: Chunk<A>;
left: Chunk<A>;
backing: Backing<A>;
depth: number;
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;
}
t).Array<Value["Type"]>.sort(compareFn?: ((a: Value["Type"], b: Value["Type"]) => number) | undefined): Value["Type"][]Sorts an array in place.
This method mutates the array and returns a reference to the same array.
sort().Array<Value["Type"]>.map<string>(callbackfn: (value: Value["Type"], index: number, array: Value["Type"][]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((v: Value["Type"]v) => `${value: Formatter<Value["Type"], string>value(v: Value["Type"]v)}`)
return `Chunk(${const size: numbersize}) { ${const values: string[]values.Array<string>.join(separator?: string): stringAdds all the elements of an array into a string, separated by the specified separator string.
join(", ")} }`
}
}
)
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(const schema: declareConstructor<
Chunk_.Chunk<Value["Type"]>,
Chunk_.Chunk<Value["Encoded"]>,
readonly [Value],
ChunkIso<Value>
>
const schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Chunk_.Chunk<Value['Type']>, readonly [Value]>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
annotateKey: (annotations: Annotations.Key<Chunk_.Chunk<Value['Type']>>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
check: (checks_0: SchemaAST.Check<Chunk_.Chunk<Value['Type']>>, ...checks: Array<SchemaAST.Check<Chunk_.Chunk<Value['Type']>>>) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Chunk_.Chunk<Value['Type']>, Chunk_.Chunk<Value['Encoded']>, readonly [Value], ChunkIso<Value>>;
make: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Chunk_.Chunk<Value['Type']>;
makeOption: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Option_.Option<Chunk_.Chunk<Value['Type']>>;
makeEffect: (input: Chunk_.Chunk<Value['Type']>, options?: MakeOptions) => Effect.Effect<Chunk_.Chunk<Value['Type']>, 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.Bottom<Chunk<Value["Type"]>, Chunk<Value["Encoded"]>, Value["DecodingServices"], Value["EncodingServices"], Declaration, ... 9 more ..., "required">["ast"]: SchemaAST.Declaration(property) Bottom<Chunk<Value["Type"]>, Chunk<Value["Encoded"]>, Value["DecodingServices"], Value["EncodingServices"], Declaration, ... 9 more ..., "required">["ast"]: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, { value: Value extends Constraintvalue })
}