UNPKG

@tsdotnet/collection-base

Version:

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/tsdotnet/collection-base/blob/master/LICENSE) ![npm-publish](https://github.com/tsdotnet/collection-base/workflows/npm-publish/badge.svg) [![npm ve

35 lines 1.03 kB
/*! * @author electricessence / https://github.com/electricessence/ * @license MIT */ import areEqual from '@tsdotnet/compare/dist/areEqual'; import IterableCollectionBase from './IterableCollectionBase'; /** * Base class for implementing an internally modifiable, eternally read-only collection. */ export default class ReadOnlyCollectionBase extends IterableCollectionBase { constructor(_equalityComparer = areEqual) { super(); this._equalityComparer = _equalityComparer; } /** * Returns the current number of entries. * @returns {number} */ get count() { return this.getCount(); } /** * Returns true if the equality comparer resolves true on any element in the collection. * @param entry * @returns {boolean} */ contains(entry) { for (const e of this) { if (this._equalityComparer(e, entry)) return true; } return false; } } //# sourceMappingURL=ReadOnlyCollectionBase.js.map