Function isArrayAnd

  • Executes a type guard for the Array<unknown> type prior to testing a condition that requires an input of Array<unknown> type, returning true only if both the type check and condition pass.

    Remarks

    This is especially useful in pipelines where the TS type checker would not detect that a type guard had been applied using other alternatives.

    Example

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

    const goodIsEmpty = G.isArrayAnd(A.isEmpty);
    goodIsEmpty([]); // true
    goodIsEmpty([5]); // false
    goodIsEmpty({}); // false

    const badIsEmpty = L.both(G.isArray, A.isEmpty);
    badIsEmpty({}); // TS compiler will not recognize G.isArray as a type guard.

    Type Parameters

    • T

    Parameters

    • condition: ((arr: unknown[]) => boolean)
        • (arr: unknown[]): boolean
        • Parameters

          • arr: unknown[]

          Returns boolean

    Returns ((x: T) => boolean)

      • (x: T): boolean
      • Parameters

        • x: T

        Returns boolean