mapErrors

CancellableTaskValidation.mapErrors

Namespace: FsToolkit.ErrorHandling

Function Signature:

('errorInput list -> 'errorOutput list)
  -> CancellableTaskValidation<'ok, 'errorInput>
  -> CancellableTaskValidation<'ok, 'errorOutput>

Applies a mapping function to the entire error list inside a CancellableTaskValidation. If the computation is Ok, the mapping function is not called and the value is propagated unchanged.

Note: mapErrors operates on the whole list at once. To map over individual errors, use mapError.

Examples

Example 1

Deduplicating errors before returning them:

let validateInput (input: FormInput) : CancellableTaskValidation<ValidatedForm, string> =
    runValidation input
    |> CancellableTaskValidation.mapErrors List.distinct

Example 2

Sorting and limiting the number of errors returned to a caller:

Example 3

Converting a list of typed errors to a list of user-facing messages:

Last updated