@mousepox/util
Version:
Miscellaneous utilities
19 lines (18 loc) • 739 B
TypeScript
import { Signal } from "./Signal";
export declare type CollectionFilter<T> = (thing: T) => boolean;
export declare type CollectionIterator<K, T> = (thing: T, key: K) => void;
export declare class Collection<K, T> {
readonly onAdd: Signal<(thing: T) => void>;
readonly onRemove: Signal<(thing: T) => void>;
protected readonly things: Map<K, T>;
get size(): number;
clear(): void;
dispose(): void;
add(key: K, thing: T): void;
remove(key: K): void;
get(key: K): T | undefined;
each(fn: CollectionIterator<K, T>, filter?: CollectionFilter<T>): void;
count(filter: CollectionFilter<T>): number;
filter(filter?: CollectionFilter<T>): T[];
first(filter: CollectionFilter<T>): T | undefined;
}