Function filterSync

  • Filters elements in an input sync iterable based on a given predicate function. Returns a new sync iterable with elements that satisfy the predicate.

    Returns

    A function that accepts an input sync iterable and returns a new sync iterable with the filtered elements.

    Example

    const input = [1, 2, 3, 4];
    const isEven = (x: number) => x % 2 === 0;
    const filteredSyncIterable = filterSync<number>(isEven)(input);

    for (const x of filteredSyncIterable) {
    console.log(x); // Logs 2, 4
    }

    Remarks

    Available as filter when imported from peter-piper/sync.

    Type Parameters

    • T

      The type of elements in the input sync iterable.

    Parameters

    • predicate: ArrayLikePredicate<T>

      A predicate function to test each element of the input sync iterable.

    Returns ((input: Iterable<T>) => Iterable<T>)

      • (input: Iterable<T>): Iterable<T>
      • Parameters

        • input: Iterable<T>

        Returns Iterable<T>

Generated using TypeDoc