Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Resultt<T>

Base class for runtime result. This class may express the context for a runtime and its result.
Highly inspired by Kotlin Result/runCatching.

see

usage ... test/appliation/result-test.ts

Type Parameters

  • T

    Type parameter for main value.

Hierarchy

  • Resultt

Index

Constructors

Properties

_value: Option<T>

Successed data of this object

Methods

  • andLastly(consumer: (() => void)): Resultt<T>
  • Return Resultt instance with doing consumer.

    Parameters

    • consumer: (() => void)
        • (): void
        • Returns void

    Returns Resultt<T>

  • filter(predicate: ((t: T) => boolean)): Resultt<T>
  • Return [Failure] if the argument predicate is evaluated as false. Internally the method filter throws runtime Error ValueNotFoundException if the predicate is false.

    Parameters

    • predicate: ((t: T) => boolean)
        • (t: T): boolean
        • Parameters

          • t: T

          Returns boolean

    Returns Resultt<T>

  • Return [Failure] if a value of this Resultt instance is null;

    Returns Resultt<T>

  • fold<R>(onSuccess: ((value?: T) => R), onFailure: ((earg?: Error) => R)): R
  • Map the value of this result to another instance typed R. If this function cannot return another instance, throw Error.

    Type Parameters

    • R

    Parameters

    • onSuccess: ((value?: T) => R)

      higher kinded function for succesing

        • (value?: T): R
        • Parameters

          • Optional value: T

          Returns R

    • onFailure: ((earg?: Error) => R)

      higher kinded function for failing

        • (earg?: Error): R
        • Parameters

          • Optional earg: Error

          Returns R

    Returns R

  • getFailure<T>(message: string): Failure<T>
  • Get Failure instance initialized with ValueNotFoundException .

    Type Parameters

    • T

    Parameters

    • message: string

    Returns Failure<T>

  • getOrDefault(elseValue: T): T
  • Get the value of this result or default value in argument

    Parameters

    • elseValue: T

    Returns T

  • getOrElse<R>(onFailure: ((earg?: Error) => R)): R
  • Get the value of type R by applying action. Shorthand for the method fold.

    Type Parameters

    • R

    Parameters

    • onFailure: ((earg?: Error) => R)

      the action on failure

        • (earg?: Error): R
        • Parameters

          • Optional earg: Error

          Returns R

    Returns R

  • getOrNull(): T
  • Get the encapsulated value of this class instance if success.

    Returns T

  • getOrThrow(e?: Error): T
  • Get a value of this result or throw error if not.

    Parameters

    • Optional e: Error

      Some Error if want. No parameter passed throw default Error.

    Returns T

  • isFailure(): boolean
  • Return true if the result was failed.

    Returns boolean

  • isSuccess(): boolean
  • Return true if the result was successed.

    Returns boolean

  • map<R>(transform: ((arg?: T) => R)): Resultt<R>
  • Map the result to another result, transforming by the argument.

    Type Parameters

    • R

    Parameters

    • transform: ((arg?: T) => R)

      callback function for mapping another Result.

        • (arg?: T): R
        • Parameters

          • Optional arg: T

          Returns R

    Returns Resultt<R>

  • mapCatching<R>(transform: ((arg?: T) => R)): Resultt<R>
  • Map the result to another result, transforming by the argument. mapCatching handle errors on executing the argument transform.

    Type Parameters

    • R

    Parameters

    • transform: ((arg?: T) => R)

      callback function for mapping another Result.

        • (arg?: T): R
        • Parameters

          • Optional arg: T

          Returns R

    Returns Resultt<R>

  • onFailure(consumer?: ((it?: Error) => void)): Resultt<T>
  • Set action on failure.

    Parameters

    • Optional consumer: ((it?: Error) => void)

      action on failure.

        • (it?: Error): void
        • Parameters

          • Optional it: Error

          Returns void

    Returns Resultt<T>

  • onSuccess(consumer: ((arg: T) => void)): Resultt<T>
  • Set an additional action on successing

    Parameters

    • consumer: ((arg: T) => void)
        • (arg: T): void
        • Parameters

          • arg: T

          Returns void

    Returns Resultt<T>

  • recover<R>(transform: ((arg?: Error) => R)): Resultt<R>
  • Type Parameters

    • R

    Parameters

    • transform: ((arg?: Error) => R)

      callback function for mapping another Result.

        • (arg?: Error): R
        • Parameters

          • Optional arg: Error

          Returns R

    Returns Resultt<R>

  • recoverCatching<R>(transform: ((arg?: Error) => R)): Resultt<R>
  • Type Parameters

    • R

    Parameters

    • transform: ((arg?: Error) => R)

      callback function for mapping another Result.

        • (arg?: Error): R
        • Parameters

          • Optional arg: Error

          Returns R

    Returns Resultt<R>

  • throwOnFailure(): void
  • toString(): string
  • Return the string expression of this class instance.

    Returns string

  • failure(error: Error): Failure<Error>
  • Create Failure instance manually

    Parameters

    • error: Error

      error

    Returns Failure<Error>

    Failure

  • runCatching<T>(supplier: (() => T)): Resultt<T>
  • Wrapping actions and return Result instance. Force the first type parameter type of Error when the action result catch Error.

    Type Parameters

    • T

    Parameters

    • supplier: (() => T)

      function to be called

        • (): T
        • Returns T

    Returns Resultt<T>

    The result of execution in argument supplier.

Generated using TypeDoc