# mapError

Namespace: `FsToolkit.ErrorHandling`

`mapError` takes a result and a normal function and returns a new result value based on the input error value and the function

## Function Signature

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

## Examples

Take the following functions for example

```fsharp
// string -> int
let getErrorCode (message: string) =
    match message with
    | "bad things happened" -> 1
    | _ -> 0
```

### Example 1

```fsharp
let result =
    Ok "all good" // Result<string, string>
    |> Result.mapError getErrorCode // Result<string, int>

// Ok "all good"
```

### Example 2

```fsharp
let result =
    Error "bad things happened" // Result<string, string>
    |> Result.mapError getErrorCode // Result<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/result/maperror.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.
