You'll never use Set
again...
AnabolicSet is built around the optional ability to customize item comparisons with a custom serializer. The uniqueness is guaranteed for the return value of the serializer.
This allows you to do things like:
const set1 = new AnabolicSet([{ id: 1 }, { id: 2 }, { id: 2 }], (obj) => obj.id) // <-- serializer
set1.values() // [{id: 1}, {id: 2}]
- custom comparing with custom serializer (similar to Java's
HashSet
andhashCode
) - improved functionality based upon native
Set
union
intersect
complement
isSubsetOf
isSupersetOf
- all native
Set
methods
- extensive & broad browser support
- blazing fast 💨 (up to 70% faster than native Set for certain operations)
const set1 = new AnabolicSet([1, 2, 3, 4, 5])
const set2 = new AnabolicSet([2, 4])
set1.addAll(...[5, 6])
set1.values() // [1, 2, 3, 4, 5, 6]
set2.isSubsetOf(set1) // true
set1.isSupersetOf(set2) // true
set2.add(7)
set1.union(set2) // AnabolicSet [1, 2, 3, 4, 5, 6, 7]
npm:
$ npm i anabolicset
import AnabolicSet from 'anabolicset'
cdn:
<script src="https://cdn.jsdelivr.net/gh/ColonelParrot/AnabolicSet@latest/src/anabolicset.min.js"></script>