# orElse Functions

Namespace: `FsToolkit.ErrorHandling`

## orElse

`orElse` returns the original `Validation` if it is `Ok`, otherwise returns the provided alternative `Validation`.

### Function Signature

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

### Examples

#### Example 1

```fsharp
let result =
    Validation.ok "First"
    |> Validation.orElse (Validation.ok "Second")

// Ok "First"
```

#### Example 2

```fsharp
let result =
    Validation.error "First"
    |> Validation.orElse (Validation.ok "Second")

// Ok "Second"
```

#### Example 3

```fsharp
let result =
    Validation.error "First"
    |> Validation.orElse (Validation.error "Second")

// Error ["Second"]
```

***

## orElseWith

`orElseWith` returns the original `Validation` if it is `Ok`, otherwise calls the given function with the error list and returns its result.

### Function Signature

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

### Examples

#### Example 1

```fsharp
let result =
    Validation.ok "First"
    |> Validation.orElseWith (fun _ -> Validation.ok "Second")

// Ok "First"
```

#### Example 2

```fsharp
let result =
    Validation.error "First"
    |> Validation.orElseWith (fun _ -> Validation.ok "Second")

// Ok "Second"
```

#### Example 3

```fsharp
let result =
    Validation.error "First"
    |> Validation.orElseWith (fun errors ->
        Validation.error $"Recovered from: %A{errors}")

// Error ["Recovered from: [\"First\"]"]
```


---

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