Hyperlinkv0.8.0-beta.28

Result

Result.tapconsteffect/Result.ts:1928
<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
mappingmap
Source effect/Result.ts:192812 lines
export 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>
} = dual(
  2,
  <A, E>(self: Result<A, E>, f: (a: A) => void): Result<A, E> => {
    if (isSuccess(self)) {
      f(self.success)
    }
    return self
  }
)