@allynet/ishod
    Preparing search index...

    Function mapErr

    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

      Returns Promise<Result<T, U>>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">
    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

      Returns Promise<Result<T, U>>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">
    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

      Returns Result<T, U>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">
    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • U

      Parameters

      • result: Promise<Result<T, E>>
      • fn: (data: E) => U | Promise<U>

      Returns Promise<Result<T, U>>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">
    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • U

      Parameters

      Returns Promise<Result<T, U>>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">
    • Map result error.

      If the result is an Err, the function will be called with the error the result contains.

      The result of the function will then be returned as a new Err result.

      On an Ok, the function will not be called, and the original Ok will be returned.

      Type Parameters

      • T
      • E
      • U

      Parameters

      Returns Result<T, U>

      const result: Result<1, "error"> = err("error");
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // "error" gets logged by the callback;
      typeof value; // Result<1, "new error">
      const result: Result<1, "error"> = ok(1);
      const value = mapErr(result, (error) => {
      console.log(error);
      return "new error" as const;
      });
      // Nothing gets logged by the callback;
      typeof value; // Result<1, "new error">