Documentation Index
Fetch the complete documentation index at: https://mintlify.com/supermacro/neverthrow/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheandThrough 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
Function that takes the Ok value and returns a Result or ResultAsync. The return value is ignored if Ok.
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
| Feature | andTee | andThrough |
|---|---|---|
| Preserves value | ✅ Yes | ✅ Yes |
| Errors ignored | ✅ Yes | ❌ No |
| Can introduce errors | ❌ No | ✅ Yes |
| Use for | Logging, metrics | Validation, required side effects |
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
andTeeinstead - ❌ Transformations → use
maporandTheninstead
Related
tee-methods
Side effects that never fail
andThen
Chain operations that transform the value