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.
const result = await fetchUser(id) .andThrough(user => { if (user.age < 18) { return err('User must be 18 or older') } return ok(undefined) }) .andThen(saveUser)// Type: ResultAsync<User, FetchError | string | SaveError>// Value is still User, not undefined
const processOrder = (order: Order) => { return okAsync(order) .andThrough(validatePaymentMethod) .andThrough(checkInventory) .andThrough(verifyAddress) .andThen(submitOrder)}// Each validation can fail, but order is preserved through the chain