Function: fail()

Creates a Failure result from a given error. Automatically wraps the error in a Promise if it is asynchronous.

Type Param

The type of the error to wrap.

Examples

import { 
import Result
Result
} from '@praha/byethrow';
const
const result: Result.Result<never, "Something went wrong">
result
=
import Result
Result
.
const fail: <"Something went wrong">(error: "Something went wrong") => Result.Result<never, "Something went wrong"> (+1 overload)
fail
('Something went wrong');
// Result.Result<never, string>
import { 
import Result
Result
} from '@praha/byethrow';
const
const result: Result.ResultAsync<never, string>
result
=
import Result
Result
.
const fail: <Promise<string>>(error: Promise<string>) => Result.ResultAsync<never, string> (+1 overload)
fail
(
var Promise: PromiseConstructor

Represents the completion of an asynchronous operation

Promise
.
PromiseConstructor.resolve<string>(value: string): Promise<string> (+2 overloads)

Creates a new resolved promise for the provided value.

@paramvalue A promise.@returnsA promise whose internal state matches the provided promise.
resolve
('Async error'));
// Result.ResultAsync<never, string>
import { 
import Result
Result
} from '@praha/byethrow';
const
const result: Result.Result<never, void>
result
=
import Result
Result
.
const fail: () => Result.ResultFor<never, never, void> (+1 overload)
fail
();
// Result.Result<never, void>

See

collect - For collect multiple Results into a single Result.

Call Signature

fail(): Result<never, void>

Returns

Result<never, void>

Call Signature

fail<E>(error): ResultFor<E, never, Awaited<E>>

Type Parameters

E

E

Parameters

error

E

Returns

ResultFor<E, never, Awaited<E>>