@esfx/collection-core Package
Provides a low-level Symbol-based API for defining common collection behaviors.
Installation
npm i @esfx/collection-core
Usage
import { Collection } from "@esfx/collection-core";
class MyCollection<T> {
private _items = new Set<T>();
// Your implementation
get count() {
return this._items.size;
}
contains(value: T) {
return this._items.has(value);
}
add(value: T) {
this._items.add(value);
}
remove(value: T) {
return this._items.delete(value);
}
clear() {
this._items.clear();
}
// Implement the `Collection` interface for cross-library consistency
get [Collection.size]() { return this.count; }
[Collection.has](value: T) { return this.contains(value); }
[Collection.add](value: T) { this.add(value); }
[Collection.delete](value: T) { return this.remove(value); }
[Collection.clear]() { this.clear(); }
[Symbol.iterator]() { return this._items.values(); }
}
Interfaces
Collection<T>
A Collection<T> describes a collection object, such as an Array or Set, that can contain other values, has a known size, and may have its contents modified.
Container<T>
A Container<T> describes a container object that can contain other values and may have its contents modified.
FixedSizeIndexedCollection<T>
IndexedCollection<T>
KeyedCollection<K, V>
KeyedContainer<K, V>
KeyedMultiCollection<K, V>
ReadonlyCollection<T>
A ReadonlyCollection<T> describes a collection object, such as an Array or Set, that can contain other values and has a known size.
ReadonlyContainer<T>
A ReadonlyContainer<T> describes a container object, such as an Array, Set, or WeakSet, that can contain other values.
ReadonlyIndexedCollection<T>
A ReadonlyIndexedCollection<T> describes an indexed collection object, such as an Array, that can contain other values, has a known size, and whose elements can be accessed by ordinal index.
ReadonlyKeyedCollection<K, V>
A ReadonlyKeyedCollection<K, V> describes a keyed collection object, such as a Map, that can contain other values, has a known size, and whose elements can be accessed by key.
ReadonlyKeyedContainer<K, V>
A ReadonlyKeyedContainer<K, V> describes a keyed container object, such as a Map or WeakMap, that can contain other values and whose elements can be accessed by key.
ReadonlyKeyedMultiCollection<K, V>
A ReadonlyKeyedMultiCollection<K, V> describes a keyed collection object that can contain other values, has a known size, and whose elements can be accessed by key, where each key can represent one or more elements.