# mapErrors

Namespace: `FsToolkit.ErrorHandling`

Similar to [Validation.mapError](/fstoolkit-errorhandling/fstoolkit.errorhandling/index/maperror.md), except that the mapping function is passed the full list of errors, rather than each one individually.

## Function Signature

```fsharp
('errorInput list -> 'errorOutput list) -> Validation<'ok, 'errorInput> 
    -> Validation<'ok, 'errorOutput>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let getErrorCode (messages: string list) =
    match messages |> List.tryFind ((=) "bad things happened") with
    | Some _ -> [1]
    | _ -> [0]
```

### Example 1

```fsharp
let result =
    Validation.ok "all good" // Validation<string, string>
    |> Validation.mapErrors getErrorCode // Validation<string, int>

// Ok "all good"
```

### Example 2

```fsharp
let result : Validation<string, int> =
    Validation.error "bad things happened" // Validation<string, string>
    |> Validation.mapErrors getErrorCode // Validation<string, int>

// Error [1]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/index/maperrors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
