• Returns resB if resA is an Ok, otherwise returns the error resA. The order of arguments is reversed because of that it is useful for partial applying.

    Type Parameters

    • U

    • E

    Parameters

    • resB: Result<E, U>

      The second result.

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

    resB if resA is a Ok.

    Examples

    import { and, err, ok } from "./result.ts";
    import { assertEquals } from "../deps.ts";

    const success = ok<number>(2);
    const failure = err("not a 2");
    const lateError = err("late error");
    const earlyError = err("early error");
    const anotherSuccess = ok("different result");

    assertEquals(and(lateError)(success), lateError);
    assertEquals(and<number, string>(success)(earlyError), earlyError);
    assertEquals(and(lateError)(failure), failure);
    assertEquals(and(anotherSuccess)(success), anotherSuccess);

Generated using TypeDoc