CollectionUtils

ceramic.CollectionUtils (Class)

Utility functions for working with Collections.

CollectionUtils provides methods for:

  • Converting arrays to collections
  • Creating filtered views of collections
  • Combining multiple collections into one

Combined and filtered collections are cached for performance, automatically updating when source collections change.

Static Members

toCollection(array: Array<toCollection.T>): Collection<ValueEntry<toCollection.T>>

Converts an array to a Collection. Each array element is wrapped in a ValueEntry.

Name Type Description
array Array<toCollection.T> The array to convert
Returns Description
Collection<ValueEntry<toCollection.T>> A new Collection containing the array elements

filtered(collection: Collection<filtered.T>, filter: Function, ?cacheKey: String): Collection<filtered.T>

Creates a filtered view of a collection.

The filtered collection automatically updates when the source changes. Use cacheKey to reuse the same filtered collection across calls.

Name Type Default Description
collection Collection<filtered.T> The source collection to filter
filter Function Function that filters the entries array
cacheKey String (optional) Optional key to cache and reuse the filtered collection
Returns Description
Collection<filtered.T> A filtered collection that updates with the source

combined(collections: Array<Collection<combined.T>>, ?cache: Bool = true): Collection<combined.T>

Combines multiple collections into a single collection.

The combined collection automatically updates when any source changes. Entries from all collections are merged in order.

Example:

var allEnemies = CollectionUtils.combined([
    groundEnemies,
    flyingEnemies,
    bossEnemies
]);
Name Type Default Description
collections Array<Collection<combined.T>> Array of collections to combine
cache Bool true Whether to cache the combined collection (default: true)
Returns Description
Collection<combined.T> A collection containing all entries from all source collections

Instance Members

new(): Void

Private Members

combinedCollections: Map

Cache for combined collections to avoid recreating them


filteredCollections: Map

Cache for filtered collections with specific cache keys

Metadata

Name Parameters
:keepSub -