Result<T>A utility type to extract the result type from a Request.
Example (Extracting a request result type)
import type { Request } from "effect"
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Extract the result type from a Request using the utility
type UserResult = Request.Result<GetUser> // Exit.Exit<string, Error>export type type Result<
T extends Request<any, any, any>
> = T extends Request<infer A, infer E, infer _R>
? Exit.Exit<A, E>
: never
A utility type to extract the result type from a Request.
Example (Extracting a request result type)
import type { Request } from "effect"
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Extract the result type from a Request using the utility
type UserResult = Request.Result<GetUser> // Exit.Exit<string, Error>
Result<function (type parameter) T in type Result<T extends Request<any, any, any>>T extends interface Request<out A, out E = never, out R = never>A Request<A, E, R> is a request from a data source for a value of type A
that may fail with an E and have requirements of type R.
Example (Defining typed requests)
import type { Request } from "effect"
// Define a request that fetches a user by ID
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Define a request that fetches all users
interface GetAllUsers extends Request.Request<ReadonlyArray<string>, Error> {
readonly _tag: "GetAllUsers"
}
Request<any, any, any>> = function (type parameter) T in type Result<T extends Request<any, any, any>>T extends interface Request<out A, out E = never, out R = never>A Request<A, E, R> is a request from a data source for a value of type A
that may fail with an E and have requirements of type R.
Example (Defining typed requests)
import type { Request } from "effect"
// Define a request that fetches a user by ID
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Define a request that fetches all users
interface GetAllUsers extends Request.Request<ReadonlyArray<string>, Error> {
readonly _tag: "GetAllUsers"
}
Request<infer function (type parameter) AA, infer function (type parameter) EE, infer function (type parameter) _R_R> ? import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<function (type parameter) AA, function (type parameter) EE>
: never