# map

### CancellableTaskValidation.map

Namespace: `FsToolkit.ErrorHandling`

Function Signature:

```fsharp
('input -> 'output)
  -> CancellableTaskValidation<'input, 'error>
  -> CancellableTaskValidation<'output, 'error>
```

Applies a mapping function to the `Ok` value inside a `CancellableTaskValidation`. If the computation contains an `Error`, the mapping function is not called and the errors are propagated unchanged.

### Examples

Note: Many use-cases requiring `map` operations can also be solved using [the `cancellableTaskValidation` computation expression](/fstoolkit-errorhandling/fstoolkit.errorhandling.icedtasks/index-1/ce.md).

#### Example 1

Transforming the inner value of a successful validation:

```fsharp
let postIdResult : CancellableTaskValidation<Guid, string> =
    savePost createPostRequest
    |> CancellableTaskValidation.map (fun (PostId postId) -> postId)
```

#### Example 2

Mapping a domain type to a DTO for serialization:

```fsharp
let getUserDto (userId: UserId) : CancellableTaskValidation<UserDto, string> =
    fetchUser userId
    |> CancellableTaskValidation.map UserDto.ofDomain
```

#### Example 3

Chaining multiple transformations:

```fsharp
let getDisplayName (userId: UserId) : CancellableTaskValidation<string, string> =
    fetchUser userId
    |> CancellableTaskValidation.map (fun user -> $"{user.FirstName} {user.LastName}")
```


---

# 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.icedtasks/index-1/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.
