ts-fortress
    Preparing search index...

    Variable swapConst

    swap: <R extends UnknownResult>(result: R) => Result<UnwrapErr<R>, UnwrapOk<R>>

    Swaps the success and error values of a Result.

    Type Declaration

      • <R extends UnknownResult>(result: R): Result<UnwrapErr<R>, UnwrapOk<R>>
      • Type Parameters

        • R extends UnknownResult

          The input UnknownResult type.

        Parameters

        • result: R

          The Result to swap.

        Returns Result<UnwrapErr<R>, UnwrapOk<R>>

        A new Result with success and error swapped.

    const okValue = Result.ok('value');

    const errValue = Result.err('error');

    assert.deepStrictEqual(Result.swap(okValue), Result.err('value'));

    assert.deepStrictEqual(Result.swap(errValue), Result.ok('error'));