Skip to main content

Overview

The andThrough method allows you to perform an operation on the Ok value that may fail, while preserving the original value if successful. Unlike andTee, errors from the operation are propagated.

Signature

(t: T) => Result<unknown, F> | ResultAsync<unknown, F>
required
Function that takes the Ok value and returns a Result or ResultAsync. The return value is ignored if Ok.
Returns: ResultAsync<T, E | F> - Original value if both succeed, or error from either operation

Usage

Validation without transformation

Multi-step validation

Side effects that must succeed

Key characteristics

andThrough preserves the original value, unlike andThen which uses the returned value.
  • Value preservation: The Ok value passes through unchanged
  • Error propagation: Errors from the through function stop the chain
  • Type addition: Error type is added to the union

Comparison: andTee vs andThrough

When to use

  • ✅ Validations that don’t transform the value
  • ✅ Critical side effects (sending emails, creating audit logs)
  • ✅ Pre-conditions that must be checked
  • ❌ Optional side effects → use andTee instead
  • ❌ Transformations → use map or andThen instead

tee-methods

Side effects that never fail

andThen

Chain operations that transform the value