Result<T, E> = Success<T> | Failure<E>
T
E
Success
Failure
A union type representing either a success or a failure.
The type of the Success value.
The type of the Failure value.
import { import ResultResult } from '@praha/byethrow'; const const doSomething: () => Result.Result<number, string>doSomething = (): import ResultResult.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.@exampleimport { Result } from '@praha/byethrow'; const doSomething = (): Result.Result<number, string> => { return Math.random() > 0.5 ? { type: 'Success', value: 10 } : { type: 'Failure', error: 'Oops' }; };@categoryCore TypesResult<number, string> => { return var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.Math.Math.random(): numberReturns a pseudorandom number between 0 and 1.random() > 0.5 ? { type: "Success"type: 'Success', value: numbervalue: 10 } : { type: "Failure"type: 'Failure', error: stringerror: 'Oops' }; };
import Result
const doSomething: () => Result.Result<number, string>
type Result<T, E> = Result.Success<T> | Result.Failure<E>
import { Result } from '@praha/byethrow'; const doSomething = (): Result.Result<number, string> => { return Math.random() > 0.5 ? { type: 'Success', value: 10 } : { type: 'Failure', error: 'Oops' }; };
Core
var Math: Math
An intrinsic object that provides basic mathematics functionality and constants.
Math.random(): number
Returns a pseudorandom number between 0 and 1.
type: "Success"
value: number
type: "Failure"
error: string