Type Alias: Result<T, E>

Result<T, E> = Success<T> | Failure<E>

A union type representing either a success or a failure.

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 doSomething: () => Result.Result<number, string>
doSomething
= ():
import Result
Result
.
type Result<T, E> = Result.Success<T> | Result.Failure<E>

A union type representing either a success or a failure.

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

const doSomething = (): Result.Result<number, string> => {
  return Math.random() > 0.5
    ? { type: 'Success', value: 10 }
    : { type: 'Failure', error: 'Oops' };
};
@categoryCore Types
Result
<number, string> => {
return
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.random(): number

Returns a pseudorandom number between 0 and 1.

random
() > 0.5
? {
type: "Success"
type
: 'Success',
value: number
value
: 10 }
: {
type: "Failure"
type
: 'Failure',
error: string
error
: 'Oops' };
};