<A>(f: (a: A) => void): <E>(self: Result<A, E>) => Result<A, E>
<A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>Runs a side-effect on the success value without altering the Result.
Details
- If the result is a
Success, callsfwith the value (return value is ignored) - If the result is a
Failure,fis not called - Returns the original
Resultunchanged (same reference) - Useful for logging, debugging, or performing mutations outside the Result chain
Example (Logging a success value)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(42),
Result.tap((n) => console.log("Got:", n))
)
// Output: "Got: 42"
console.log(Result.isSuccess(result))
// Output: trueexport const const tap: {
<A>(f: (a: A) => void): <E>(
self: Result<A, E>
) => Result<A, E>
<A, E>(
self: Result<A, E>,
f: (a: A) => void
): Result<A, E>
}
Runs a side-effect on the success value without altering the Result.
Details
- If the result is a
Success, calls f with the value (return value is ignored)
- If the result is a
Failure, f is not called
- Returns the original
Result unchanged (same reference)
- Useful for logging, debugging, or performing mutations outside the Result chain
Example (Logging a success value)
import { pipe, Result } from "effect"
const result = pipe(
Result.succeed(42),
Result.tap((n) => console.log("Got:", n))
)
// Output: "Got: 42"
console.log(Result.isSuccess(result))
// Output: true
tap: {
<function (type parameter) A in <A>(f: (a: A) => void): <E>(self: Result<A, E>) => Result<A, E>A>(f: (a: A) => voidf: (a: Aa: function (type parameter) A in <A>(f: (a: A) => void): <E>(self: Result<A, E>) => Result<A, E>A) => void): <function (type parameter) E in <E>(self: Result<A, E>): Result<A, 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>(f: (a: A) => void): <E>(self: Result<A, E>) => Result<A, E>A, function (type parameter) E in <E>(self: Result<A, E>): Result<A, 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) A in <A>(f: (a: A) => void): <E>(self: Result<A, E>) => Result<A, E>A, function (type parameter) E in <E>(self: Result<A, E>): Result<A, E>E>
<function (type parameter) A in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, 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>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>E>, f: (a: A) => voidf: (a: Aa: function (type parameter) A in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>A) => void): 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>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>E>
} = import dualdual(
2,
<function (type parameter) A in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, 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>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>E>, f: (a: A) => voidf: (a: Aa: function (type parameter) A in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>A) => void): 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>, f: (a: A) => void): Result<A, E>A, function (type parameter) E in <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E>E> => {
if (const isSuccess: <A, E>(
self: Result<A, E>
) => self is Success<A, E>
Checks whether a Result is a Success.
When to use
Use to narrow a known Result to the Success variant.
Details
- Acts as a TypeScript type guard, narrowing to
Success<A, E>
- After narrowing, you can access
.success to read the value
Example (Narrowing to success)
import { Result } from "effect"
const result = Result.succeed(42)
if (Result.isSuccess(result)) {
console.log(result.success)
// Output: 42
}
isSuccess(self: Result<A, E>self)) {
f: (a: A) => voidf(self: Result<A, E>(parameter) self: {
_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;
}
self.Success<A, E>.success: Asuccess)
}
return self: Result<A, E>self
}
)