@allynet/ishod
    Preparing search index...

    Function tryMap

    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • const TT extends Primitive
      • const EE extends Primitive

      Parameters

      Returns Promise<Result<TT, E | EE>>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • const TT extends Primitive
      • const EE extends Primitive

      Parameters

      Returns Result<TT, E | EE>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • const TT extends Primitive
      • EE

      Parameters

      Returns Promise<Result<TT, E | EE>>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • const TT extends Primitive
      • EE

      Parameters

      Returns Result<TT, E | EE>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • TT
      • const EE extends Primitive

      Parameters

      Returns Promise<Result<TT, E | EE>>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • TT
      • const EE extends Primitive

      Parameters

      Returns Result<TT, E | EE>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • TT
      • EE

      Parameters

      Returns Promise<Result<TT, E | EE>>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";
    • Try to map a result.

      Works similarly to the map function, but the callback returns a result.

      The returned result is treated as the new result.

      If the original result is an Err, the callback will not be called, and the original Err will be returned.

      Type Parameters

      • T
      • E
      • TT
      • EE

      Parameters

      Returns Result<TT, E | EE>

      const result = tryMap(ok(1), (data) => {
      return ok(data + 1);
      });
      // result is an Ok with the value 2;
      const result = tryMap(err("error"), (data) => {
      return ok(data + 1);
      });
      // result is an Err with the error "error";
      const result = tryMap(ok(1), (data) => {
      return err("new error");
      });
      // result is an Err with the error "new error";