ts-fortress
    Preparing search index...

    Variable toOptionalConst

    toOptional: <R extends UnknownResult>(result: R) => Optional<UnwrapOk<R>>

    Converts a Result to an Optional.

    This conversion is useful when you want to discard error information and only care about whether an operation succeeded. The error information is lost in this conversion, so use it when error details are not needed.

    If the Result is Ok, returns Some with the value. If the Result is Err, returns None.

    Type Declaration

      • <R extends UnknownResult>(result: R): Optional<UnwrapOk<R>>
      • Type Parameters

        • R extends UnknownResult

          The input UnknownResult type.

        Parameters

        • result: R

          The Result to convert.

        Returns Optional<UnwrapOk<R>>

        An Optional<UnwrapOk<R>> containing the success value or representing None.

    const okValue = Result.ok(7);

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

    assert.deepStrictEqual(Result.toOptional(okValue), Optional.some(7));

    assert.deepStrictEqual(Result.toOptional(errValue), Optional.none);