> 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/taskresultoption/ce.md).

# Computation Expression

### TaskResultOption Computation Expression

Namespace: `FsToolkit.ErrorHandling`

### Examples

#### Example 1

The [TaskResultOption.map2 example](/fstoolkit-errorhandling/fstoolkit.errorhandling/taskresultoption/map2.md#example-1) can be written using the `taskResultOption` computation expression as below:

```fsharp
// Task<Result<UserTweet option, exn>>
taskResultOption {
  let! post = getPostById samplePostId
  let! user = getUserById post.UserId
  return userTweet post user
}
```

#### Example 2

The `taskResultOption` CE supports binding from multiple compatible types, allowing you to mix `TaskResultOption`, `TaskResult`, `Result`, `Option`, `Task`, and `Async` values without manual conversion:

```fsharp
// parseMode: string -> Result<Mode, string>
// loadUniverse: Mode -> Task<Result<Universe, string>>

// Task<Result<Report option, string>>
taskResultOption {
  // Bind from Result<Mode, string> directly (no manual conversion needed)
  let! mode = parseMode "fast"

  // Bind from Task<Result<Universe, string>> directly
  let! universe = loadUniverse mode

  return generateReport universe
}
```

#### Supported Source Types

The `taskResultOption` CE supports `let!` and `return!` with the following types:

| Type                               | Behavior                                          |
| ---------------------------------- | ------------------------------------------------- |
| `Task<Result<'ok option, 'error>>` | Identity (the CE's native type)                   |
| `Task<Result<'ok, 'error>>`        | `Ok` value is wrapped in `Some`                   |
| `Task<'ok option>`                 | `Some`/`None` is wrapped in `Ok`                  |
| `Task<'ok>`                        | Value is wrapped in `Some` and then `Ok`          |
| `Result<'ok, 'error>`              | `Ok` value is wrapped in `Some`, lifted to `Task` |
| `Choice<'ok, 'error>`              | Converted to `Result`, then same as `Result`      |
| `'ok option`                       | `Some`/`None` wrapped in `Ok`, lifted to `Task`   |
| `Async<Result<'ok, 'error>>`       | `Ok` value is wrapped in `Some`                   |
| `Async<'ok>`                       | Value is wrapped in `Some` and then `Ok`          |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/taskresultoption/ce.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
