# traverseAsyncResult

### Option.traverseAsyncResult

Namespace: `FsToolkit.ErrorHandling`

Function Signature:

```fsharp
('a -> Async<Result<'b,'c>>) -> 'a option -> Async<Result<'b option, 'c>>
```

Note that `traverse` is the same as `map >> sequence`. See also [Option.sequenceAsyncResult](/fstoolkit-errorhandling/fstoolkit.errorhandling/option/sequenceasyncresult.md).

See also Scott Wlaschin's [Understanding traverse and sequence](https://fsharpforfunandprofit.com/posts/elevated-world-4/).

### Examples

#### Example 1

Say we have a function to get a number from a database (asynchronously), and multiply our input by that number if it's found:

```fsharp
let tryMultiplyWithDatabaseValue: float -> Async<Result<float, string>> = // ...
```

If we start with an optional vaue, then we could map this funciton using `Option.traverseAsyncResult` as follows:

```fsharp
let input = Some 1.234

input // float option
|> Option.traverseAsyncResult tryMultiplyWithDatabaseValue // Async<Result<float option, string>>
```

If we combine this with the [AsyncResult computation expression](/fstoolkit-errorhandling/fstoolkit.errorhandling/asyncresult/ce.md), we could directly `let!` the output:

```fsharp
asyncResult {
    let input = Some 1.234

    let! output = // float option
        input // float option
        |> Option.traverseAsyncResult tryMultiplyWithDatabaseValue // Async<Result<float option, string>>
}
```


---

# 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/option/traverseasyncresult.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.
