Prelude API
    Preparing search index...

    Function every

    • Tests whether all elements in an iterable pass the provided predicate function. Similar to Array.prototype.every(), but works with any iterable.

      Type Parameters

      • T

        Type of elements in the iterable

      Parameters

      • predicate: (value: T, index: number) => boolean

        Function to test each element and its index

      Returns (values: Iterable<T>) => boolean

      A function that takes an iterable and returns true if all elements pass the test

      // Check if all numbers are positive
      const allPositive = every((n: number) => n > 0)([1, 2, 3, 4])
      // Result: true
      // Check if all numbers are even
      const allEven = every((n: number) => n % 2 === 0)([2, 4, 5, 6])
      // Result: false (5 is odd)
      // Using the index parameter
      const indexMatchesValue = every((val, idx) => val === idx)([0, 1, 2, 3])
      // Result: true

      some - For testing if at least one element passes a test