Prelude API
    Preparing search index...

    Function cartesianProduct

    • Creates a generator that yields all possible pairs between elements of two iterables. If only one iterable is provided, it creates pairs from the same iterable.

      Type Parameters

      • T

        Type of elements in the first iterable

      • U extends Iterable<unknown, any, any> | undefined

        Type of the second iterable or undefined

      Parameters

      • Optionalg: U

        Optional second iterable. If omitted, pairs are created from elements in h

      Returns (h: Iterable<T>) => Generator<[T, U extends undefined ? T : Value<U>]>

      A function that takes an iterable and returns a generator of pairs

      Pairs [a, b] representing the cartesian product of the two iterables

      // Cartesian product of two arrays
      const pairs = [...cartesianProduct([4, 5, 6])([1, 2, 3])]
      // Result: [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]]
      // Cartesian product of array with itself
      const selfPairs = [...cartesianProduct()([1, 2, 3])]
      // Result: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]]