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

# Function: mapError()

Applies a transformation function to the error value of a [Result](/byethrow/api/types/Result.Result.md) or [ResultAsync](/byethrow/api/types/Result.ResultAsync.md).
If the input is a [Success](/byethrow/api/types/Result.Success.md), it will be returned unchanged.

## Type Param

**R1**

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

## Type Param

**E2**

The transformed error value type.

## Examples

**Failure Case (unchanged)**

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

const result = Result.pipe(
  Result.fail('NotFound'),
  Result.mapError((error) => new Error(error)),
);
// { type: 'Failure', error: Error('NotFound') }
```

**Success Case (unchanged)**

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

const result = Result.pipe(
  Result.succeed(123),
  Result.mapError((error) => new Error(error)),
);
// { type: 'Success', value: 123 }
```

## See

[pipe](/byethrow/api/functions/Result.pipe.md) - It is recommended to use this function with the [pipe](/byethrow/api/functions/Result.pipe.md) function for better readability and composability.

## Call Signature

> **mapError**\<`R1`, `E2`>(`fn`): (`result`) => [`ResultFor`](/byethrow/api/types/Result.ResultFor.md)\<`R1`, [`InferSuccess`](/byethrow/api/types/Result.InferSuccess.md)\<`R1`>, `E2`>

### Type Parameters

#### R1

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

#### E2

`E2`

### Parameters

#### fn

(`a`) => `E2`

### Returns

(`result`) => [`ResultFor`](/byethrow/api/types/Result.ResultFor.md)\<`R1`, [`InferSuccess`](/byethrow/api/types/Result.InferSuccess.md)\<`R1`>, `E2`>

## Call Signature

> **mapError**\<`E1`, `E2`>(`fn`): \<`R1`>(`result`) => [`ResultFor`](/byethrow/api/types/Result.ResultFor.md)\<`R1`, [`InferSuccess`](/byethrow/api/types/Result.InferSuccess.md)\<`R1`>, `E2`>

### Type Parameters

#### E1

`E1`

#### E2

`E2`

### Parameters

#### fn

(`a`) => `E2`

### Returns

\<`R1`>(`result`) => [`ResultFor`](/byethrow/api/types/Result.ResultFor.md)\<`R1`, [`InferSuccess`](/byethrow/api/types/Result.InferSuccess.md)\<`R1`>, `E2`>
