API reference@evolu/commonSet › addToSet

function addToSet<T>(set: ReadonlySet<T>, item: T): NonEmptyReadonlySet<T>;

Defined in: packages/common/src/Set.ts:127

Returns a new readonly set with an item added.

If the item already exists, returns a new set with the same elements (still a new reference for change detection).

Example

addToSet(new Set([1, 2]), 3); // Set {1, 2, 3}
addToSet(new Set([1, 2]), 2); // Set {1, 2} (new reference)