signal-desktop/ts/util/setUtil.ts
Evan Hahn 5ce26eb91a
Speaking indicator for group calls
Co-authored-by: Peter Thatcher <peter@signal.org>
Co-authored-by: Jim Gustafson <jim@signal.org>
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
2022-02-08 12:30:33 -06:00

29 lines
732 B
TypeScript

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