<S extends Schema.Constraint>(schema: S): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Option.Option<S["Type"]>Creates a synchronous maker that returns Option.some with the constructed
value on success, or Option.none when construction fails with schema issues.
When to use
Use when you need to validate schema constructor input and only care whether
construction succeeds, without exposing SchemaIssue.Issue details.
Gotchas
Only causes made entirely of schema issues are converted to Option.none.
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause.
export function function makeOption<
S extends Schema.Constraint
>(
schema: S
): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Option.Option<S["Type"]>
Creates a synchronous maker that returns Option.some with the constructed
value on success, or Option.none when construction fails with schema issues.
When to use
Use when you need to validate schema constructor input and only care whether
construction succeeds, without exposing SchemaIssue.Issue details.
Gotchas
Only causes made entirely of schema issues are converted to Option.none.
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause.
makeOption<function (type parameter) S in makeOption<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => Option.Option<S["Type"]>S extends import SchemaSchema.Constraint>(schema: S extends Schema.Constraintschema: function (type parameter) S in makeOption<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => Option.Option<S["Type"]>S) {
const const parser: (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
never
>
parser = function makeEffect<
S extends Schema.Constraint
>(
schema: S
): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<S["Type"], SchemaIssue.Issue>
Creates an effectful maker for the schema's decoded type side.
When to use
Use to construct decoded schema values in Effect while preserving
construction failures as SchemaIssue.Issue values in the error channel.
Details
The returned function accepts constructor input, applies constructor defaults,
runs type-side validation unless checks are disabled, and fails with a
SchemaIssue.Issue when construction fails.
makeEffect(schema: S extends Schema.Constraintschema)
return (input: S["~type.make.in"]input: function (type parameter) S in makeOption<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => Option.Option<S["Type"]>S["~type.make.in"], options: Schema.MakeOptionsoptions?: import SchemaSchema.MakeOptions): import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) S in makeOption<S extends Schema.Constraint>(schema: S): (input: S["~type.make.in"], options?: Schema.MakeOptions) => Option.Option<S["Type"]>S["Type"]> => {
const const exit: Exit.Exit<
S["Type"],
SchemaIssue.Issue
>
exit = import EffectEffect.const runSyncExit: <A, E>(
effect: Effect<A, E>
) => Exit.Exit<A, E>
Runs an effect synchronously and captures the outcome safely as an Exit type, which
represents the outcome (success or failure) of the effect.
When to use
Use to find out whether an effect succeeded or failed,
including any defects, without dealing with asynchronous operations.
Details
The Exit type represents the result of the effect. Successful effects are
wrapped in Success, and failed effects are wrapped in Failure with a
Cause.
If the effect contains asynchronous operations, runSyncExit will
return an Failure with a Die cause, indicating that the effect cannot be
resolved synchronously.
Example (Observing synchronous results as Exit)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.succeed(1)))
// Output:
// {
// _id: "Exit",
// _tag: "Success",
// value: 1
// }
console.log(Effect.runSyncExit(Effect.fail("my error")))
// Output:
// {
// _id: "Exit",
// _tag: "Failure",
// cause: {
// _id: "Cause",
// _tag: "Fail",
// failure: "my error"
// }
// }
Example (Capturing async work as a Die cause)
import { Effect } from "effect"
console.log(Effect.runSyncExit(Effect.promise(() => Promise.resolve(1))))
// Output:
// {
// _id: 'Exit',
// _tag: 'Failure',
// cause: {
// _id: 'Cause',
// _tag: 'Die',
// defect: [Fiber #0 cannot be resolved synchronously. This is caused by using runSync on an effect that performs async work] {
// fiber: [FiberRuntime],
// _tag: 'AsyncFiberException',
// name: 'AsyncFiberException'
// }
// }
// }
runSyncExit(const parser: (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
never
>
parser(input: S["~type.make.in"]input, options: Schema.MakeOptionsoptions))
if (import ExitExit.const isSuccess: <A, E>(
self: Exit<A, E>
) => self is Success<A, E>
Checks whether an Exit is a Success.
When to use
Use as a type guard to narrow Exit<A, E> to Success<A, E> and access the
value property.
Example (Narrowing to success)
import { Exit } from "effect"
const exit = Exit.succeed(42)
if (Exit.isSuccess(exit)) {
console.log(exit.value) // 42
}
isSuccess(const exit: Exit.Exit<
S["Type"],
SchemaIssue.Issue
>
exit)) {
return import OptionOption.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(const exit: Exit.Success<
S["Type"],
SchemaIssue.Issue
>
const exit: {
_tag: "Success";
value: A;
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;
}
exit.Success<S["Type"], Issue>.value: S["Type"]value)
}
import InternalSchemaCauseInternalSchemaCause.function getSchemaIssueOrThrow(
cause: Cause.Cause<SchemaIssue.Issue>,
message: string
): SchemaIssue.Issue
getSchemaIssueOrThrow(const exit: Exit.Failure<
S["Type"],
SchemaIssue.Issue
>
const exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
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;
}
exit.Failure<S["Type"], Issue>.cause: Cause.Cause<E>(property) Failure<S["Type"], Issue>.cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause, "Option adapter can only return none for schema issues")
return import OptionOption.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
}
}