> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Function: orElse()

> **orElse**\<`F`>(`fn`): \<`O1`>(`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O1` | `ReturnType`\<`F`>, [`InferSome`](/api/types/Option.InferSome.md)\<`O1`> | [`InferSome`](/api/types/Option.InferSome.md)\<`F`>>

Chains a fallback computation for an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md).
If the input is a [Some](/api/types/Option.Some.md), it is returned unchanged.
Otherwise, the provided function is called, and its result is returned as-is.

## Type Parameters

### F

`F` _extends_ () => [`OptionMaybeAsync`](/api/types/Option.OptionMaybeAsync.md)\<`any`>

The fallback function type.

## Parameters

### fn

`F`

## Returns

\<`O1`>(`option`) => [`OptionFor`](/api/types/Option.OptionFor.md)\<`O1` | `ReturnType`\<`F`>, [`InferSome`](/api/types/Option.InferSome.md)\<`O1`> | [`InferSome`](/api/types/Option.InferSome.md)\<`F`>>

## Examples

**None Case**

```ts
import { Option } from 'byenull';

const option = Option.pipe(
  Option.none(),
  Option.orElse(() => Option.some('default')),
);
// { type: 'Some', value: 'default' }
```

**Some Case (fn is never called)**

```ts
import { Option } from 'byenull';

const option = Option.pipe(
  Option.some('value'),
  Option.orElse(() => Option.some('default')),
);
// { type: 'Some', value: 'value' }
```

## See

- [unwrap](/api/functions/Option.unwrap.md) - For returning a plain value instead of a fallback Option.
- [pipe](/api/functions/Option.pipe.md) - It is recommended to use this function with the [pipe](/api/functions/Option.pipe.md) function for better readability and composability.
