Prelude API
    Preparing search index...

    Function compact

    • Creates a generator that filters out null and undefined values from an iterable.

      Type Parameters

      • T

        Type of elements in the iterable

      Parameters

      • values: Iterable<T>

        The source iterable to filter

      Returns Generator<NonNullable<T>>

      A generator yielding only non-null, non-undefined values

      All non-nullish values from the source iterable

      // Filter out nullish values
      const results = [...compact([1, null, 2, undefined, 3])]
      // Result: [1, 2, 3]

      defined - For filtering out only undefined values (preserving null)