Skip to main content

Result <T, E>

A class representing the result of a failable operation

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

  • new Result<T, E>(value, error): Result<T, E>
  • Create a new Result representing the status of a failable operation


    Parameters

    • value: T
    • optionalerror: E = null

    Returns Result<T, E>

Properties

error

error: E

value

value: T

Accessors

err

  • get err(): boolean
  • Returns whether the operation was a failure


    Returns boolean

ok

  • get ok(): boolean
  • Returns whether the operation was a success


    Returns boolean

Methods

errorAsDOM

  • errorAsDOM(customMessage): (string | Element)[]
  • Convert the Result.Error message into a list of DOM elements as usable by the likes of ElementDOMScreen.setStatus).

    Always returns an empty list for nullish errors


    Parameters

    • customMessage: string | Element | readonly (string | Element)[] = null

      A custom message to be used as prefix

    Returns (string | Element)[]

    The list of DOM elements

unwrap

  • unwrap(): T
  • Unwrap the result This either returns the successful return of the operation, or throws the error it reported


    Returns T

staticfailure

  • failure(error): Result<any, Error>
  • Build a Result for a failed operation


    Parameters

    • error: Error

    Returns Result<any, Error>

staticsuccess

  • success<T>(value): Result<T, any>
  • Build a Result for a successful operation


    Parameters

    • value: T

    Returns Result<T, any>