Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Err<T, E>

An Err instance is the failure variant instance of the Result type, representing a failure outcome from an operation which may fail. For a full discussion, see the module docs.

Type parameters

  • T

    The type which would be wrapped in an Ok variant of Result.

  • E

    The type wrapped in this Err variant of Result.

Hierarchy

  • Err

Implements

Index

Constructors

constructor

  • new Err(error: E | null): Err
  • Create an instance of Result.Err with new.

    Note: While you may create the Result type via normal JavaScript class construction, it is not recommended for the functional style for which the library is intended. Instead, use Result.err.

    // Avoid:
    const anErr = new Result.Err('alas, failure');
    
    // Prefer:
    const anErr = Result.err('alas, failure');

    Note that you may explicitly pass Unit to the Err constructor to create a Result<T, Unit>. However, you may not call the Err constructor with null or undefined to get that result (the type system won't allow you to construct it that way). Instead, for convenience, you can simply call Result.err(), which will construct the type correctly.

    throws

    If you pass null or undefined.

    Parameters

    • error: E | null

      The value to wrap in a Result.Err.

      Note: null and undefined are allowed by the type signature so that the constructor may throw on those rather than constructing a type like Result<number, undefined>.

    Returns Err

Properties

error

error: E

The wrapped error value.

variant

variant: Err = Variant.Err

Err is always Variant.Err.

Methods

and

andThen

  • andThen<U>(this: Result<T, E>, andThenFn: function): Result<U, E>

ap

chain

  • chain<U>(this: Result<T, E>, chainFn: function): Result<U, E>

equals

  • equals(this: Result<T, E>, comparison: Result<T, E>): boolean

flatMap

  • flatMap<U>(this: Result<T, E>, flatMapFn: function): Result<U, E>

isErr

  • isErr(this: Result<T, E>): this is Err<T, E>

isOk

  • isOk(this: Result<T, E>): this is Ok<T, E>

map

  • Method variant for Result.map

    Type parameters

    • U

    Parameters

    • this: Result<T, E>
    • mapFn: function
        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns Result<U, E>

mapErr

  • mapErr<F>(this: Result<T, E>, mapErrFn: function): Result<T, F>

mapOr

  • mapOr<U>(this: Result<T, E>, orU: U, mapFn: function): U
  • Method variant for Result.mapOr

    Type parameters

    • U

    Parameters

    • this: Result<T, E>
    • orU: U
    • mapFn: function
        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns U

mapOrElse

  • mapOrElse<U>(this: Result<T, E>, orElseFn: function, mapFn: function): U
  • Method variant for Result.mapOrElse

    Type parameters

    • U

    Parameters

    • this: Result<T, E>
    • orElseFn: function
        • (err: E): U
        • Parameters

          • err: E

          Returns U

    • mapFn: function
        • (t: T): U
        • Parameters

          • t: T

          Returns U

    Returns U

match

or

orElse

  • orElse<F>(this: Result<T, E>, orElseFn: function): Result<T, F>

toJSON

toMaybe

toString

  • toString(this: Result<T, E>): string

unsafelyUnwrap

  • unsafelyUnwrap(): never

unsafelyUnwrapErr

  • unsafelyUnwrapErr(): E

unwrapOr

  • unwrapOr(this: Result<T, E>, defaultValue: T): T

unwrapOrElse

  • unwrapOrElse(this: Result<T, E>, elseFn: function): T

Static unwrapErr

  • unwrapErr<F>(theErr: Err<F, any>): F
  • Unwrap the contained error . A convenience method for functional idioms.

    A common scenario where you might want to use this is in a pipeline of functions:

    import Result, { Ok } from 'true-myth/result';
    
    function getMessages(results: Array<Result<string, Error>>): Array<number> {
    return maybeStrings
    .filter(Result.isErr)
    .map(Err.unwrapErr)
    .map(e => e.message);
    }

    Type parameters

    • F

    Parameters

    • theErr: Err<F, any>

    Returns F

Generated using TypeDoc