> For the complete documentation index, see [llms.txt](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/result/maperror.md).

# 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
```
