<A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A2, E2>(f: Result<A2, E2>): <A, E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>
<A2>(right: NotFunction<A2>): <A, E>(self: Result<A, E>) => Result<A2, E>
<A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<
A2,
E | E2
>
<A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>
<A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>
<A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>Provides a flexible variant of flatMap that accepts multiple input shapes.
When to use
Use to sequence a next step that may be a Result, a function, or a plain
value.
Details
The second argument can be:
- A function
(a: A) => Result<A2, E2>(same asflatMap) - A function
(a: A) => A2(auto-wrapped insucceed) - A
Result<A2, E2>value (ignores the success ofself) - A plain value
A2(auto-wrapped insucceed, ignoresself)
If self is a Failure, the second argument is never evaluated.
Example (Chaining Result values with different argument types)
import { pipe, Result } from "effect"
// With a function returning a Result
const a = pipe(
Result.succeed(1),
Result.andThen((n) => Result.succeed(n + 1))
)
// With a plain mapping function
const b = pipe(
Result.succeed(1),
Result.andThen((n) => n + 1)
)
// With a constant value
const c = pipe(Result.succeed(1), Result.andThen("done"))
console.log(a, b, c)export const const andThen: {
<A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A2, E2>(f: Result<A2, E2>): <A, E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A, A2>(f: (a: A) => A2): <E>(
self: Result<A, E>
) => Result<A2, E>
<A2>(right: NotFunction<A2>): <A, E>(
self: Result<A, E>
) => Result<A2, E>
<A, E, A2, E2>(
self: Result<A, E>,
f: (a: A) => Result<A2, E2>
): Result<A2, E | E2>
<A, E, A2, E2>(
self: Result<A, E>,
f: Result<A2, E2>
): Result<A2, E | E2>
<A, E, A2>(
self: Result<A, E>,
f: (a: A) => A2
): Result<A2, E>
<A, E, A2>(
self: Result<A, E>,
f: NotFunction<A2>
): Result<A2, E>
}
Provides a flexible variant of
flatMap
that accepts multiple input shapes.
When to use
Use to sequence a next step that may be a Result, a function, or a plain
value.
Details
The second argument can be:
- A function
(a: A) => Result<A2, E2> (same as flatMap)
- A function
(a: A) => A2 (auto-wrapped in succeed)
- A
Result<A2, E2> value (ignores the success of self)
- A plain value
A2 (auto-wrapped in succeed, ignores self)
If self is a Failure, the second argument is never evaluated.
Example (Chaining Result values with different argument types)
import { pipe, Result } from "effect"
// With a function returning a Result
const a = pipe(
Result.succeed(1),
Result.andThen((n) => Result.succeed(n + 1))
)
// With a plain mapping function
const b = pipe(
Result.succeed(1),
Result.andThen((n) => n + 1)
)
// With a constant value
const c = pipe(Result.succeed(1), Result.andThen("done"))
console.log(a, b, c)
andThen: {
<function (type parameter) A in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A, function (type parameter) A2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>E2>(f: (a: A) => Result<A2, E2>f: (a: Aa: function (type parameter) A in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A) => 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<function (type parameter) A2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>E2>): <function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E | E2>E>(self: Result<A, E>self: 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<function (type parameter) A in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A, function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E | E2>E>) => 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<function (type parameter) A2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E | E2>E | function (type parameter) E2 in <A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(self: Result<A, E>) => Result<A2, E | E2>E2>
<function (type parameter) A2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>E2>(f: Result<A2, E2>f: 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<function (type parameter) A2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>E2>): <function (type parameter) A in <A, E>(self: Result<A, E>): Result<A2, E | E2>A, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E | E2>E>(self: Result<A, E>self: 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<function (type parameter) A in <A, E>(self: Result<A, E>): Result<A2, E | E2>A, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E | E2>E>) => 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<function (type parameter) A2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>A2, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E | E2>E | function (type parameter) E2 in <A2, E2>(f: Result<A2, E2>): <A, E>(self: Result<A, E>) => Result<A2, E | E2>E2>
<function (type parameter) A in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A, function (type parameter) A2 in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A2>(f: (a: A) => A2f: (a: Aa: function (type parameter) A in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A) => function (type parameter) A2 in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A2): <function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E>E>(self: Result<A, E>self: 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<function (type parameter) A in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A, function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E>E>) => 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<function (type parameter) A2 in <A, A2>(f: (a: A) => A2): <E>(self: Result<A, E>) => Result<A2, E>A2, function (type parameter) E in <E>(self: Result<A, E>): Result<A2, E>E>
<function (type parameter) A2 in <A2>(right: NotFunction<A2>): <A, E>(self: Result<A, E>) => Result<A2, E>A2>(right: NotFunction<A2>right: type NotFunction<T> = T extends Function ? never : TExcludes function types from a union, keeping only non-function members.
When to use
Use to filter out callable types from a union.
Details
Returns never if the entire union consists of function types.
Example (Filtering out functions)
import type { Types } from "effect"
type Result = Types.NotFunction<string | (() => void) | number>
// string | number
NotFunction<function (type parameter) A2 in <A2>(right: NotFunction<A2>): <A, E>(self: Result<A, E>) => Result<A2, E>A2>): <function (type parameter) A in <A, E>(self: Result<A, E>): Result<A2, E>A, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E>E>(self: Result<A, E>self: 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<function (type parameter) A in <A, E>(self: Result<A, E>): Result<A2, E>A, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E>E>) => 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<function (type parameter) A2 in <A2>(right: NotFunction<A2>): <A, E>(self: Result<A, E>) => Result<A2, E>A2, function (type parameter) E in <A, E>(self: Result<A, E>): Result<A2, E>E>
<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E, function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E2>(self: Result<A, E>self: 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<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E>, f: (a: A) => Result<A2, E2>f: (a: Aa: function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A) => 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E2>): 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E | function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: (a: A) => Result<A2, E2>): Result<A2, E | E2>E2>
<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E, function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E2>(self: Result<A, E>self: 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<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E>, f: Result<A2, E2>f: 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E2>): 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>A2, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E | function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: Result<A2, E2>): Result<A2, E | E2>E2>
<function (type parameter) A in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>E, function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A2>(self: Result<A, E>self: 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<function (type parameter) A in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>E>, f: (a: A) => A2f: (a: Aa: function (type parameter) A in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A) => function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A2): 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<function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>A2, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: (a: A) => A2): Result<A2, E>E>
<function (type parameter) A in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>A, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>E, function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>A2>(self: Result<A, E>self: 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<function (type parameter) A in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>A, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>E>, f: NotFunction<A2>f: type NotFunction<T> = T extends Function ? never : TExcludes function types from a union, keeping only non-function members.
When to use
Use to filter out callable types from a union.
Details
Returns never if the entire union consists of function types.
Example (Filtering out functions)
import type { Types } from "effect"
type Result = Types.NotFunction<string | (() => void) | number>
// string | number
NotFunction<function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>A2>): 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<function (type parameter) A2 in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>A2, function (type parameter) E in <A, E, A2>(self: Result<A, E>, f: NotFunction<A2>): Result<A2, E>E>
} = import dualdual(
2,
<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E, function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E2>(
self: Result<A, E>self: 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<function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E>,
f: | ((a: A) => Result<A2, E2> | A2)
| Result<A2, E2>
| A2
f: ((a: Aa: function (type parameter) A in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A) => 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E2> | function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2) | 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2, function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E2> | function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2
): 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<function (type parameter) A2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>A2, function (type parameter) E in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E | function (type parameter) E2 in <A, E, A2, E2>(self: Result<A, E>, f: ((a: A) => Result<A2, E2> | A2) | Result<A2, E2> | A2): Result<A2, E | E2>E2> =>
const flatMap: {
<A, A2, E2>(f: (a: A) => Result<A2, E2>): <E>(
self: Result<A, E>
) => Result<A2, E | E2>
<A, E, A2, E2>(
self: Result<A, E>,
f: (a: A) => Result<A2, E2>
): Result<A2, E | E2>
}
flatMap(self: Result<A, E>self, (a: Aa) => {
const const out: anyout = import isFunctionisFunction(f: | ((a: A) => Result<A2, E2> | A2)
| Result<A2, E2>
| A2
f) ? f: | ((a: A) => Result<A2, E2> | A2)
| Result<A2, E2>
| A2
f(a: Aa) : f: | ((a: A) => Result<A2, E2> | A2)
| Result<A2, E2>
| A2
f
return const isResult: (
input: unknown
) => input is Result<unknown, unknown>
Checks whether a value is a Result (either Success or Failure).
When to use
Use to validate unknown input before operating on it as a Result.
Details
- Returns
true for both Success and Failure variants
- Acts as a TypeScript type guard, narrowing to
Result<unknown, unknown>
Example (Checking if a value is a Result)
import { Result } from "effect"
console.log(Result.isResult(Result.succeed(1)))
// Output: true
console.log(Result.isResult({ value: 1 }))
// Output: false
isResult(const out: anyout) ? const out: Result<unknown, unknown>out : 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: anyout)
})
)