@allynet/ishod
    Preparing search index...

    Function map

    • Map result data.

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

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

      Returns Promise<Result<U, E>>

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

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

      Returns Promise<Result<U, E>>

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

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • const U extends Primitive

      Parameters

      Returns Result<U, E>

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

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • U

      Parameters

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

      Returns Promise<Result<U, E>>

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

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • U

      Parameters

      Returns Promise<Result<U, E>>

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

      If the result is an Ok, the function will be called with the data the result contains.

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

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

      Type Parameters

      • T
      • E
      • U

      Parameters

      Returns Result<U, E>

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