zip

CancellableTaskValidation.zip

Namespace: FsToolkit.ErrorHandling

Function Signature:

CancellableTaskValidation<'left, 'error>
  -> CancellableTaskValidation<'right, 'error>
  -> CancellableTaskValidation<'left * 'right, 'error>

Takes two CancellableTaskValidation values, runs them serially (left then right), and returns a tuple of the results. Errors from both computations are accumulated — if both return Error, all errors are collected into a single list.

Unlike parallelZip, computations run one after the other.

Examples

Example 1

Combining two validation results into a tuple:

let validateUserAndRole (userId: UserId) : CancellableTaskValidation<User * Role, string> =
    CancellableTaskValidation.zip
        (fetchAndValidateUser userId)
        (fetchAndValidateRole userId)

Example 2

Using zip inside a larger computation expression:

Example 3

Accumulating errors from two independent validations:

Last updated