@mikuroxina/mini-fn
    Preparing search index...

    Function andThen

    • Returns fn(v) if resA is an Ok(v), otherwise returns the error resA. This is an implementation of FlatMap. The order of arguments is reversed because of that it is useful for partial applying.

      Type Parameters

      • T
      • U
      • E

      Parameters

      Returns (resA: Result.Result<E, T>) => Result.Result<E, U>

      fn() if resA is an Ok.

      Examples

      const sqrtThenToString = andThen(
      (num: number): Result<string, string> =>
      num < 0
      ? err("num must not be negative")
      : ok(Math.sqrt(num).toString()),
      );

      expect(sqrtThenToString(ok(4))).toStrictEqual(ok("2"));
      expect(sqrtThenToString(ok(-1))).toStrictEqual(err("num must not be negative"));
      expect(sqrtThenToString(err("not a number"))).toStrictEqual(err("not a number"));