javascript-collections-framework
    Preparing search index...

    Function copyOfSet

    • Returns an immutable set of the distinct elements of elements, in first-seen order, deciding sameness by options as a HashSet does: SameValueZero by default, a derived key, or an equivalence. The whole source is read before any key, equals or hash call, so a callback that changes the source does not affect the result. Given a set this function or setOf returned with the same key or equivalence (or none on both), it may return that set.

      Time: O(n) average for n elements, plus the key or equivalence calls.

      Type Parameters

      • E

      Parameters

      • elements: Iterable<E>

        The elements.

      • Optionaloptions: HashSetOptions<E> | null

        key or equivalence; null or undefined means none.

      Returns ReadonlySetCollection<E>

      An immutable set.

      TypeError when elements is not iterable (null and undefined included) or the options are invalid (both given, a key that is not a function, an equivalence without equals and hash functions, or options that are not an object).

      copyOfSet(['Ann', 'ann', 'Bo'], { key: (name) => name.toLowerCase() })
      // ImmutableSet(2) {'Ann', 'Bo'}