# Function: unwrap()

Extracts the success value from a [Result](../types/Result.Result.md) or [ResultAsync](../types/Result.ResultAsync.md).

If the input is a [Failure](../types/Result.Failure.md), it will throw the error or return the default value if provided.

## Type Param

**R**

The input [Result](../types/Result.Result.md) or [ResultAsync](../types/Result.ResultAsync.md).

## Type Param

**T**

The default value type (optional).

## Examples

**Success Case (without default)**

```ts
import { Result } from '@praha/byethrow';

const result = Result.succeed(42);
const value = Result.unwrap(result); // 42
```

**Success Case (with default)**

```ts
import { Result } from '@praha/byethrow';

const result = Result.succeed(42);
const value = Result.unwrap(result, 0); // 42
```

**Failure Case (without default) - throws error**

```ts
import { Result } from '@praha/byethrow';

const result = Result.fail('error');
Result.unwrap(result); // throws 'error'
```

**Failure Case (with default)**

```ts
import { Result } from '@praha/byethrow';

const result = Result.fail('error');
const value = Result.unwrap(result, 0); // 0
```

## See

[assertSuccess](./Result.assertSuccess.md) - When used with [assertSuccess](./Result.assertSuccess.md), you can safely unwrap the [Result](../types/Result.Result.md).

## Call Signature

> **unwrap**\<`R`>(`result`): `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](../types/Result.ResultMaybeAsync.md)\<`any`, `any`>

### Parameters

#### result

`R`

### Returns

`true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

## Call Signature

> **unwrap**\<`R`, `T`>(`result`, `defaultValue`): `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : `T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](../types/Result.ResultMaybeAsync.md)\<`any`, `any`>

#### T

`T`

### Parameters

#### result

`R`

#### defaultValue

`T`

### Returns

`true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : `T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

## Call Signature

> **unwrap**\<`R`>(): (`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](../types/Result.ResultMaybeAsync.md)\<`any`, `any`>

### Returns

(`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<[`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

## Call Signature

> **unwrap**\<`R`, `T`>(`defaultValue`): (`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : `T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>

### Type Parameters

#### R

`R` _extends_ [`ResultMaybeAsync`](../types/Result.ResultMaybeAsync.md)\<`any`, `any`>

#### T

`T`

### Parameters

#### defaultValue

`T`

### Returns

(`result`) => `true` _extends_ `HasPromise`\<`R`> ? `Promise`\<`T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>> : `T` | [`InferSuccess`](../types/Result.InferSuccess.md)\<`R`>
