Prelude API
    Preparing search index...
    • Creates a consumer that checks if all values in an async iterable are unique.

      Type Parameters

      • T

        The type of values in the async iterable

      • K = T

        The type of keys used for uniqueness checks (defaults to T)

      Parameters

      • Optionalf: (value: T) => K | Promise<K>

        Optional function to transform values into keys for uniqueness checking

      Returns Consumer<T, boolean>

      A consumer function that returns a promise resolving to a boolean

      This function processes an async iterable and determines if all values (or derived keys) are unique. It returns true if all values are unique, and false as soon as it encounters a duplicate. The function can use an optional mapping function to transform values into keys before checking uniqueness, which is useful for complex objects.

      // Check if all numbers are unique
      const allUnique = await G.pipe(
      G.ofIterable([1, 2, 3, 4, 5]),
      G.areUnique()
      ); // true

      const hasDuplicates = await G.pipe(
      G.ofIterable([1, 2, 3, 3, 5]),
      G.areUnique()
      ); // false

      // Check uniqueness using a specific property
      const users = [
      { id: 1, name: 'Alice' },
      { id: 2, name: 'Bob' },
      { id: 3, name: 'Charlie' }
      ];

      const uniqueIds = await G.pipe(
      G.ofIterable(users),
      G.areUnique(user => user.id)
      ); // true