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

# Function: unwrap()

> **unwrap**\<`D`>(`defaultValue`): \<`O`>(`option`) => `Unwrapped`\<`O`, `D`>

Extracts the value from an [Option](/api/types/Option.Option.md) or [OptionAsync](/api/types/Option.OptionAsync.md).
If the input is a [None](/api/types/Option.None.md), the default value is returned.

## Type Parameters

### D

`D`

The default value type.

## Parameters

### defaultValue

`D`

## Returns

\<`O`>(`option`) => `Unwrapped`\<`O`, `D`>

## Examples

**Some Case**

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

const value = Option.pipe(
  Option.some(2),
  Option.unwrap(0),
);
// 2
```

**None Case**

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

const empty: Option.Option<number> = Option.none();

const value = Option.pipe(
  empty,
  Option.unwrap(0),
);
// 0
```

**Nullish Default**

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

const value: number | null = Option.pipe(
  Option.some(2),
  Option.unwrap(null),
);
```

## See

- [orElse](/api/functions/Option.orElse.md) - For recovering with a fallback Option instead of a plain value.
- [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.
