// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import { every } from './iterables'; const add = (set: Readonly>, item: T): Set => new Set(set).add(item); export const remove = ( set: Readonly>, ...items: ReadonlyArray ): Set => { const clone = new Set(set); for (const item of items) { clone.delete(item); } return clone; }; export const toggle = ( set: Readonly>, item: Readonly, shouldInclude: boolean ): Set => (shouldInclude ? add : remove)(set, item); export const isEqual = ( a: Readonly>, b: Readonly> ): boolean => a === b || (a.size === b.size && every(a, item => b.has(item)));