javascript-collections-framework
    Preparing search index...

    Interface ReadonlySetCollection<E>

    The read-only view of a set: a collection with no two equal members, readable the way native Set is (size, has, keys, values, entries, forEach), so native set methods and new Set(set) accept it.

    Two sets are equal when they have the same size and each has every member of the other, whatever their insertion order.

    function overlap<E>(a: ReadonlySetCollection<E>, b: ReadonlySetCollection<E>): E[] {
    return a.toArray().filter((element) => b.has(element))
    }
    interface ReadonlySetCollection<E> {
        revision: number;
        size: number;
        "[equalsSymbol]"(other: unknown): boolean;
        "[hashCodeSymbol]"(hash: HashFunction): number;
        "[iterator]"(): IterableIterator<E>;
        cursor(): Cursor<E>;
        entries(): IterableIterator<[E, E]>;
        equals(other: unknown): boolean;
        forEach(
            action: (element: E, same: E, set: ReadonlySetCollection<E>) => void,
            thisArg?: unknown,
        ): void;
        has(element: E): boolean;
        isEmpty(): boolean;
        keys(): IterableIterator<E>;
        toArray(): E[];
        toJSON(): E[];
        toString(): string;
        values(): IterableIterator<E>;
    }

    Type Parameters

    • E

    Hierarchy (View Summary)

    Index
    revision: number

    A number that changes on every change to the contents — adding, removing or replacing an element — and never on a read. Watch it to detect changes; its exact values are unspecified. Time: O(1).

    size: number

    The number of elements. Time: O(1).

    • The value-equality protocol; delegates to equals. Time: as equals.

      Parameters

      • other: unknown

      Returns boolean

    • Returns an iterator over the elements in iteration order.

      Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.

      Returns IterableIterator<E>

      A new iterator.

      ConcurrentModificationError (from next()) when elements of a fail-fast collection are added or removed after the iterator is created, including through a cursor.

    • Returns an iterator over [member, member] pairs, as native Set does.

      Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.

      Returns IterableIterator<[E, E]>

      A new iterator.

    • Returns whether other is equal to this collection, as the collection's family defines; otherwise only the collection itself. Time: as the implementation documents.

      Parameters

      • other: unknown

        Any value.

      Returns boolean

      true when equal.

    • Calls action(member, member, set) for each member, with this set to thisArg, as native Set does.

      Time: O(n) plus the calls.

      Parameters

      • action: (element: E, same: E, set: ReadonlySetCollection<E>) => void

        Called with each member twice and the set.

      • OptionalthisArg: unknown

        The this value for action.

      Returns void

      TypeError when action is not a function.

    • Returns whether some element is equal to element under the collection's equality (SameValueZero unless the collection says otherwise). Time: as the implementation documents.

      Parameters

      • element: E

        The value to look for.

      Returns boolean

      true when an equal element is present.

    • Returns whether the collection has no elements.

      Time: O(1).

      Returns boolean

      size === 0.

    • Returns an iterator over the members, as values() does (native Set has both).

      Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.

      Returns IterableIterator<E>

      A new iterator.

    • Returns a new array of the elements in iteration order; changing it does not change the collection.

      Time: O(n).

      Returns E[]

      A new array.

    • Returns a new array of the elements, so JSON.stringify writes the collection as an array.

      Time: O(n).

      Returns E[]

      A new array.

    • Returns the class name, size and elements, e.g. ArrayList(3) [1, 2, 'a'].

      Time: O(length of the output) for flat contents; each level of nested arrays or collections copies its text once more.

      Returns string

      The text.

    • Returns an iterator over the members.

      Time: O(1) to create; each step amortised O(1) unless the implementation documents otherwise.

      Returns IterableIterator<E>

      A new iterator.