Function: mapError()

Applies a transformation function to the error value of a Result or ResultAsync. If the input is a Success, it will be returned unchanged.

Type Param

The input Result or ResultAsync.

Type Param

The transformed error value type.

Examples

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

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

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

See

pipe - It is recommended to use this function with the pipe function for better readability and composability.

Call Signature

mapError<R1, E2>(fn): (result) => ResultFor<R1, InferSuccess<R1>, E2>

Defined in: functions/map-error.ts:44

Type Parameters

R1

R1 extends ResultMaybeAsync<any, any>

E2

E2

Parameters

fn

(a) => E2

Returns

(result): ResultFor<R1, InferSuccess<R1>, E2>

Parameters

result

R1

Returns

ResultFor<R1, InferSuccess<R1>, E2>

Call Signature

mapError<E1, E2>(fn): <R1>(result) => ResultFor<R1, InferSuccess<R1>, E2>

Defined in: functions/map-error.ts:45

Type Parameters

E1

E1

E2

E2

Parameters

fn

(a) => E2

Returns

<R1>(result): ResultFor<R1, InferSuccess<R1>, E2>

Type Parameters

R1

R1 extends ResultMaybeAsync<any, E1>

Parameters

result

R1

Returns

ResultFor<R1, InferSuccess<R1>, E2>