<
const I extends
| Iterable<Result<any, any>>
| Record<string, Result<any, any>>
>(
input: I
): [I] extends [ReadonlyArray<Result<any, any>>]
? Result<
{
-readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>]
? R
: never
},
I[number] extends never
? never
: [I[number]] extends [Result<any, infer L>]
? L
: never
>
: [I] extends [Iterable<Result<infer R, infer L>>]
? Result<Array<R>, L>
: Result<
{
-readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>]
? R
: never
},
I[keyof I] extends never
? never
: [I[keyof I]] extends [Result<any, infer L>]
? L
: never
>Collects a structure of Results into a single Result of collected values.
When to use
Use to collect independent Result values into one Result while preserving
the original structure.
Details
Accepts:
- A tuple/array: returns
Resultwith a tuple/array of success values - A struct (record): returns
Resultwith a struct of success values - An iterable: returns
Resultwith an array of success values
Short-circuits on the first Failure encountered; later elements are not inspected.
Example (Collecting a tuple and a struct)
import { Result } from "effect"
// Tuple
const tuple = Result.all([Result.succeed(1), Result.succeed("two")])
console.log(tuple)
// Output: { _tag: "Success", success: [1, "two"], ... }
// Struct
const struct = Result.all({ x: Result.succeed(1), y: Result.fail("err") })
console.log(struct)
// Output: { _tag: "Failure", failure: "err", ... }export const const all: <
I extends
| Iterable<Result<any, any>>
| Record<string, Result<any, any>>
>(
input: I
) => [I] extends [ReadonlyArray<Result<any, any>>]
? Result<
{
-readonly [K in keyof I]: [I[K]] extends [
Result<infer R, any>
]
? R
: never
},
I[number] extends never
? never
: [I[number]] extends [
Result<any, infer L>
]
? L
: never
>
: [I] extends [
Iterable<Result<infer R, infer L>>
]
? Result<Array<R>, L>
: Result<
{
-readonly [K in keyof I]: [I[K]] extends [
Result<infer R, any>
]
? R
: never
},
I[keyof I] extends never
? never
: [I[keyof I]] extends [
Result<any, infer L>
]
? L
: never
>
Collects a structure of Results into a single Result of collected values.
When to use
Use to collect independent Result values into one Result while preserving
the original structure.
Details
Accepts:
- A tuple/array: returns
Result with a tuple/array of success values
- A struct (record): returns
Result with a struct of success values
- An iterable: returns
Result with an array of success values
Short-circuits on the first Failure encountered; later elements are not inspected.
Example (Collecting a tuple and a struct)
import { Result } from "effect"
// Tuple
const tuple = Result.all([Result.succeed(1), Result.succeed("two")])
console.log(tuple)
// Output: { _tag: "Success", success: [1, "two"], ... }
// Struct
const struct = Result.all({ x: Result.succeed(1), y: Result.fail("err") })
console.log(struct)
// Output: { _tag: "Failure", failure: "err", ... }
all: <const function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I extends interface Iterable<T, TReturn = any, TNext = any>Iterable<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>> | type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>>>(
input: const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>input: function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I
) => [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I] extends [interface ReadonlyArray<T>ReadonlyArray<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>>] ? type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<
{ -readonly [function (type parameter) KK in keyof function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I]: [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[function (type parameter) KK]] extends [type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<infer function (type parameter) RR, any>] ? function (type parameter) RR : never },
function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[number] extends never ? never : [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[number]] extends [type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, infer function (type parameter) LL>] ? function (type parameter) LL : never
>
: [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I] extends [interface Iterable<T, TReturn = any, TNext = any>Iterable<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<infer function (type parameter) RR, infer function (type parameter) LL>>] ? type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<interface Array<T>Array<function (type parameter) RR>, function (type parameter) LL>
: type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<
{ -readonly [function (type parameter) KK in keyof function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I]: [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[function (type parameter) KK]] extends [type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<infer function (type parameter) RR, any>] ? function (type parameter) RR : never },
function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[keyof function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I] extends never ? never : [function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I[keyof function (type parameter) I in <const I extends Iterable<Result<any, any>> | Record<string, Result<any, any>>>(input: I): [I] extends [ReadonlyArray<Result<any, any>>] ? Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[number] extends never ? never : [I[number]] extends [Result<any, infer L>] ? L : never> : [I] extends [Iterable<Result<infer R, infer L>>] ? Result<Array<R>, L> : Result<{ -readonly [K in keyof I]: [I[K]] extends [Result<infer R, any>] ? R : never; }, I[keyof I] extends never ? never : [I[keyof I]] extends [Result<any, infer L>] ? L : never>I]] extends [type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, infer function (type parameter) LL>] ? function (type parameter) LL : never
> = (
input: | Iterable<Result<any, any>>
| Record<string, Result<any, any>>
input: interface Iterable<T, TReturn = any, TNext = any>Iterable<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>> | type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>>
): type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any> => {
if (var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator in input: | Iterable<Result<any, any>>
| Record<string, Result<any, any>>
input) {
const const out: Array<Result<any, any>>out: interface Array<T>Array<type Result<A, E = never> = Success<A, E> | Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<any, any>> = []
for (const const e: Result<any, any>e of input: | Iterable<Result<any, any>>
| Record<string, Result<any, any>>
input) {
if (const isFailure: <A, E>(
self: Result<A, E>
) => self is Failure<A, E>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(const e: Result<any, any>e)) {
return const e: Failure<any, any>const e: {
_tag: "Failure";
_op: "Failure";
failure: 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;
}
e
}
const out: Array<Result<any, any>>out.Array<Result<any, any>>.push(...items: Result<any, any>[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const e: Success<any, any>const e: {
_tag: "Success";
_op: "Success";
success: 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;
}
e.Success<any, any>.success: anysuccess)
}
return const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(const out: Array<Result<any, any>>out)
}
const const out: Record<string, any>out: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, any> = {}
for (const const key: stringkey of var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.keys(o: {}): string[] (+1 overload)Returns the names of the enumerable string properties and methods of an object.
keys(input: | Iterable<Result<any, any>>
| Record<string, Result<any, any>>
input)) {
const const e: Result<any, any>e = input: | Iterable<Result<any, any>>
| Record<string, Result<any, any>>
input[const key: stringkey]
if (const isFailure: <A, E>(
self: Result<A, E>
) => self is Failure<A, E>
Checks whether a Result is a Failure.
When to use
Use to narrow a known Result to the Failure variant.
Details
- Acts as a TypeScript type guard, narrowing to
Failure<A, E>
- After narrowing, you can access
.failure to read the error value
Example (Narrowing to failure)
import { Result } from "effect"
const result = Result.fail("oops")
if (Result.isFailure(result)) {
console.log(result.failure)
// Output: "oops"
}
isFailure(const e: Result<any, any>e)) {
return const e: Failure<any, any>const e: {
_tag: "Failure";
_op: "Failure";
failure: 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;
}
e
}
const out: Record<string, any>out[const key: stringkey] = const e: Success<any, any>const e: {
_tag: "Success";
_op: "Success";
success: 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;
}
e.Success<any, any>.success: anysuccess
}
return const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(const out: Record<string, any>out)
}