# map

Namespace: `FsToolkit.ErrorHandling`

`map` applies a transformation to the value inside a `Result` if it represents a successful result (`Ok`). It allows you to perform a computation on the value while preserving the success/error status of the original `Result`. If the original `Result` is an `Error`, `map` does nothing and returns the same `Error` unchanged.

## Function Signature

```fsharp
('okInput -> 'okOutput) -> Result<'okInput, 'error> -> Result<'okOutput, 'error>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let remainingCharacters (prompt: string) =
    280 - prompt.Length
```

### Example 1

```fsharp
let result =
    Ok "foo" // Result<string, string>
    |> Result.map remainingCharacters // Result<int, string>

// Ok 277
```

### Example 2

```fsharp
let result =
    Error "bad things happened" // Result<string, string>
    |> Result.map remainingCharacters // Result<int, string>

// Error "bad things happened"
```


---

# 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/map.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.
