3
GitHub - ColonelParrot/AnabolicSet: 💪 Javascript Set on steroids.
source link: https://github.com/ColonelParrot/AnabolicSet
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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}]
Featuring...
- custom comparing with custom serializer (similar to Java's
HashSet
andhashCode
) improved functionality based upon native
Set
- 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]
Import
npm:
$ npm i anabolicset
import { AnabolicSet } from 'anabolicset/src/anabolicset'
cdn:
<script src="https://cdn.jsdelivr.net/gh/ColonelParrot/AnabolicSet@latest/src/anabolicset.min.js"></script>
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK