Function filter

Filters an array based on a predicate function.

const takePositives = filter((x: number) => x > 0);
const a = takePositives([1, 2, 3]); // [1, 2, 3]
const b = takePositives([-1, 0, 1]); // [1]
  • Type Parameters

    • T

    Parameters

    • fn: ((x: unknown) => x is T)
        • (x): x is T
        • Parameters

          • x: unknown

          Returns x is T

    Returns (<U>(source: readonly U[]) => Extract<U, T>[])

      • <U>(source): Extract<U, T>[]
      • Type Parameters

        • U

        Parameters

        • source: readonly U[]

        Returns Extract<U, T>[]

  • Type Parameters

    • V

    Parameters

    • fn: ((x: V) => boolean)
        • (x): boolean
        • Parameters

          Returns boolean

    Returns (<T>(source: readonly V[]) => T[])

      • <T>(source): T[]
      • Type Parameters

        • T

        Parameters

        • source: readonly V[]

        Returns T[]