parallelZip

CancellableTaskValidation.parallelZip

Namespace: FsToolkit.ErrorHandling

Function Signature:

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

Takes two CancellableTaskValidation values, starts them concurrently, and returns a tuple of the results once both complete. Errors from both computations are accumulated — if both return Error, all errors are collected into a single list.

Unlike zip, both computations are started before waiting for either to complete, which can improve throughput when the two operations are independent.

Examples

Example 1

Fetching two independent resources in parallel while collecting any errors:

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

Example 2

Using parallelZip inside a computation expression:

Example 3

Concurrently validating independent fields and accumulating all errors:

Last updated