Function branch

  • Applies the transform corresponding to the first matching condition, or the fallback transform if no predicate from conditions matches.

    Example

    import * as L from "flurp/logic";

    const f = L.branch([
    [N.isGt(100), N.multiply(0.9)],
    [N.isGt(50), N.subtract(5)],
    [N.isGt(0), L.identity],
    ], L.always(0));

    f(500); // 450
    f(100); // 95
    f(30); // 30
    f(-10) // 0

    Type Parameters

    • T

    • U

    Parameters

    • conditions: [((x: T) => boolean), ((x: T) => U)][]
    • fallback: ((x: T) => U)
        • (x: T): U
        • Parameters

          • x: T

          Returns U

    Returns ((x: T) => U)

      • (x: T): U
      • Parameters

        • x: T

        Returns U