# orElse Functions

### CancellableTaskValidation.orElse

Namespace: `FsToolkit.ErrorHandling`

Returns the original result unchanged if it is `Ok`, otherwise returns the provided alternative `CancellableTaskValidation`.

Note: `CancellableTaskValidation` accumulates errors as `'error list`. The `orElseWith` overload receives the full error list.

### Function Signature:

```fsharp
CancellableTaskValidation<'ok, 'errorOutput>
  -> CancellableTaskValidation<'ok, 'errorInput>
  -> CancellableTaskValidation<'ok, 'errorOutput>
```

### Examples

#### Example 1

```fsharp
CancellableTaskValidation.error "First"
|> CancellableTaskValidation.orElse (CancellableTaskValidation.singleton "Second")
// evaluates to Ok "Second"
```

#### Example 2

When the input is already `Ok`, the alternative is ignored:

```fsharp
CancellableTaskValidation.singleton "First"
|> CancellableTaskValidation.orElse (CancellableTaskValidation.error "Second")
// evaluates to Ok "First"
```

***

### CancellableTaskValidation.orElseWith

Namespace: `FsToolkit.ErrorHandling`

Returns the original result unchanged if it is `Ok`, otherwise calls the given function with the accumulated error list and returns its result. The alternative function is **not** evaluated unless the input is `Error`.

### Function Signature:

```fsharp
('errorInput list -> CancellableTaskValidation<'ok, 'errorOutput>)
  -> CancellableTaskValidation<'ok, 'errorInput>
  -> CancellableTaskValidation<'ok, 'errorOutput>
```

### Examples

#### Example 1

```fsharp
CancellableTaskValidation.error "First"
|> CancellableTaskValidation.orElseWith (fun _ -> CancellableTaskValidation.error "Second")
// evaluates to Error ["Second"]
```

#### Example 2

Falling back to a secondary validation strategy when the primary fails:

```fsharp
let validateInput (input: string) : CancellableTaskValidation<ParsedInput, string> =
  strictValidation input
  |> CancellableTaskValidation.orElseWith (fun errs ->
      lenientValidation input)
```


---

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