mapError

CancellableTaskValidation.mapError

Namespace: FsToolkit.ErrorHandling

Function Signature:

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

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

Note: mapError applies the function element-wise to each error in the list. To transform the entire error list at once, use mapErrors.

Examples

Example 1

Wrapping low-level errors in a domain error type:

let validateUser (input: UserInput) : CancellableTaskValidation<User, AppError> =
    fetchAndValidateUser input
    |> CancellableTaskValidation.mapError AppError.ValidationError

Example 2

Converting errors to strings for display:

Example 3

Lifting errors from one domain to another at a boundary:

Last updated