logo
byethrow
Guide
Examples
API Reference
Guide
Examples
API Reference
logo
byethrow
@praha/byethrow

Modules

Result

Types

Type Alias: Failure<E>
Type Alias: InferFailure<T>
Type Alias: InferSuccess<T>
Type Alias: Result<T, E>
Type Alias: ResultAsync<T, E>
Type Alias: ResultFor<R, T, E>
Type Alias: ResultMaybeAsync<T, E>
Type Alias: Success<T>

Functions

Function: andThen()
Function: andThrough()
Function: assertFailure()
Function: assertSuccess()
Function: bind()
Function: combine()
Function: do()
Function: fail()
Function: inspect()
Function: inspectError()
Function: isFailure()
Function: isResult()
Function: isSuccess()
Function: map()
Function: mapError()
Function: orElse()
Function: parse()
Function: pipe()
Function: succeed()
Function: try()
Function: unwrap()
Function: unwrapError()

Last Updated:

Previous PageType Alias: Result<T, E>
Next PageType Alias: ResultFor<R, T, E>

#Type Alias: ResultAsync<T, E>

ResultAsync<T, E> = Promise<Result<T, E>>

Defined in: result.ts:92

An asynchronous variant of Result, wrapped in a Promise.

#Type Parameters

#T

T

The type of the Success value.

#E

E

The type of the Failure value.

#Example

import { 
import Result
Result
} from '@praha/byethrow';
const
const fetchData: () => Result.ResultAsync<string, Error>
fetchData
= async ():
import Result
Result
.
type ResultAsync<T, E> = Promise<Result.Result<T, E>>

An asynchronous variant of Result , wrapped in a Promise.

@typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@example
import { Result } from '@praha/byethrow';

const fetchData = async (): Result.ResultAsync<string, Error> => {
  try {
    const data = await fetch('...');
    return { type: 'Success', value: await data.text() };
  } catch (err) {
    return { type: 'Failure', error: err as Error };
  }
};
@categoryCore Types
ResultAsync
<string, Error> => {
try { const
const data: Response
data
= await
function fetch(input: string | URL | Request, init?: RequestInit): Promise<Response> (+1 overload)

MDN Reference

fetch
('...');
return {
type: "Success"
type
: 'Success',
value: string
value
: await
const data: Response
data
.
Body.text(): Promise<string>

MDN Reference

text
() };
} catch (
function (local var) err: unknown
err
) {
return {
type: "Failure"
type
: 'Failure',
error: Error
error
:
function (local var) err: unknown
err
as Error };
} };