Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ITryFactory

A factory for producing an ITry representing the result of some operation that may throw an error.

Hierarchy

  • ITryFactory

Index

Methods

error

  • error<T>(error: Error | string, cause?: Error): ITry<T>
  • Creates a ITry from a erronous operation.

    TryFactory.error("foobar").orThrow() // => throws Error("foobar")
    

    Type parameters

    • T

      Type of the value produced by the operation on success.

    Parameters

    • error: Error | string
    • Optional cause: Error

    Returns ITry<T>

    A ITry representing the erronous operation.

flatOf

  • flatOf<T>(operation: Supplier<ITry<T>>, cause?: Error): ITry<T>
  • Creates a ITry from an operation that may succeed or fail to produce a ITry.

    Type parameters

    • T

      Type of the success value of the produced ITry.

    Parameters

    • operation: Supplier<ITry<T>>

      Am operation that produces a ITry, but may fail to do so by throwing an error.

    • Optional cause: Error

    Returns ITry<T>

    The produced ITry or a ITry representing the error.

of

  • of<T>(operation: Supplier<T>, cause?: Error): ITry<T>
  • Creates a ITry from an operation that may succeed or fail to return a value.

     // returns JSON object or throws if input is not valid JSON string
    TryFactory.of(() => JSON.parse(input)).orThrow()
    

    Type parameters

    • T

      Type of the value produced by the operation on success.

    Parameters

    • operation: Supplier<T>

      An operation that produces a value, but may fail to do so by throwing an error.

    • Optional cause: Error

    Returns ITry<T>

    A ITry representing the result of the operation.

success

  • success<T>(value: T): ITry<T>
  • Creates a ITry from a successfully produced value.

    TryFactory.success("foobar").orThrow() // => "foobar"
    

    Type parameters

    • T

      Type of the value produced by the operation on success.

    Parameters

    • value: T

      The successful result of some operation.

    Returns ITry<T>

    A ITry representing the sucessful operation.

Generated using TypeDoc