Prelude API
    Preparing search index...

    Function unsafePermutations

    • Returns a generator that yields all permutations of the input iterable. WARNING: This loads the entire input iterable into memory, which can be unsafe for large collections. For a safer version with constrained memory usage, use combinations.ts.

      Type Parameters

      • T

        The type of elements in the iterable

      Parameters

      • Optionalk: number

        Optional length of each permutation (defaults to the length of the input)

      Returns (g: Iterable<T>) => Generator<T[]>

      All possible permutations as arrays

      G.pipe(
      [1, 2, 3],
      G.unsafePermutations(),
      G.array
      ) // [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

      G.pipe(
      [1, 2, 3],
      G.unsafePermutations(2),
      G.array
      ) // [[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]