@bemedev/better-set
v0.2.1
Published
A better Set implementation with customizable equality check
Maintainers
Readme
@bemedev/better-set
A better Set implementation with customizable equality and set algebra
helpers.
Install
pnpm add @bemedev/better-setFeatures
- Custom equality comparison for complex values
createBetterSetand aliascreateSet- Full iterable support with
for...of union,intersection,difference,symmetricDifferenceisSubsetOf,isSupersetOf,isDisjointFromsize,isEmpty,toArray,entries,keys,values,forEach,clear,delete
Usage
import { createBetterSet } from '@bemedev/better-set';
const set = createBetterSet<{ id: number }>((a, b) => a.id === b.id);
set.add({ id: 1 }, { id: 1 }, { id: 2 });
console.log(set.size); // 2
console.log(set.toArray); // [ { id: 1 }, { id: 2 } ]API
createBetterSet<T>(equals?: (a: T, b: T) => boolean)
equals— optional custom comparator used to detect duplicates.- Returns
BetterSet<T>.
BetterSet properties and methods
add(...items)has(item)sizeisEmptyclear()delete(item)forEach(callback)toArrayentrieskeysvaluesreplaceItems(source)for swapping in aSetor anotherBetterSetunion(other, equals)intersection(other, equals)difference(other, equals)symmetricDifference(other, equals)isSubsetOf(other)isSupersetOf(other)isDisjointFrom(other)
CHANGELOG
Read CHANGELOG.md for release notes.
License
MIT
Author
chlbri ([email protected])
