ts-data-forge
    Preparing search index...
    • 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 Parameters

      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);