andThen
Pass an Ok value to another function returning a Result. An Err passes through unchanged, without calling the function. Inspired by Rust's Result::and_then, exposed as a standalone function rather than a method.
Usage
andThen(result, next)
Parameters
The result to continue. Plain structurally compatible Results work too.
Called once with the success value, or not at all on failure. Must return a synchronous Result.
Returns
Result<U, E | F>. Returns the callback's Result or the original Err by reference. Unlike Rust's method, the input and callback may have different error types; their union is preserved.
Exceptions and async work
Unexpected callback exceptions propagate; andThen does not catch or normalize them. Use attempt at throwing boundaries. Async callbacks are not accepted: await attemptAsync first, then use andThen for synchronous continuation. For another async step, use an explicit isErr guard and await the operation.
See also
orElse— continue on failure insteadattempt/attemptAsync— capture unsafe work- Result & Errors