Function ifIsString

  • Applies stringTransform if the argument is a string, and otherTransform if it is not.

    Example

    import * as G from "flurp/guard";
    import * as S from "flurp/string";
    import * as L from "flurp/logic";

    const lengthOrZero = G.ifIsString(S.length, L.always(0));
    lengthOrZero("50"); // 2
    lengthOrZero(50); // 0

    Type Parameters

    • T

    • U

    Parameters

    • stringTransform: ((x: string) => U)
        • (x: string): U
        • Parameters

          • x: string

          Returns U

    • otherTransform: ((x: T) => U)
        • (x: T): U
        • Parameters

          • x: T

          Returns U

    Returns ((x: string | T) => U)

      • (x: string | T): U
      • Parameters

        • x: string | T

        Returns U