← Back to index
class Collection
extends Array <T>

Collection is a wrapper around Array with utility functions for common operations.

Constructors
🔗
Collection ()
Type Parameters
Properties
🔗
areDistinct : boolean

Returns true if all items in collection are distinct.

🔗
first : T

Get first item in collection.

🔗
last : T

Get last item in collection.

🔗
x : T extends number ? NumberUtil : never

Returns utility functions that can be applied to collections of certain types

Methods
🔗
concat (...items: ConcatArray<T>[]): Collection<T>
🔗
concat (...items: (T | ConcatArray<T>)[]): Collection<T>
🔗
count (filterFn: (val: T) => boolean): number

Counts items in collection that match given predicate.

🔗
filter <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S): Collection<S>
🔗
filter (predicate: (value: T, index: number, array: T[]) => unknown): Collection<T>
🔗
intersection (...collections: Collection<T>[]): Collection<T>

Returns collection with items that are in all given collections.

🔗
iter (): CollectionIterable<T>

Creates an iterator of the collection.

🔗
leading (count: number): Collection<T>

Returns given amount of entries from the start of the collection.

🔗
map <U>(callbackfn: (value: T, index: number, array: T[]) => U): Collection<U>
🔗
partition (partitionSize: number): Collection2D<T>

Partitions collection into sub-collections of given size.

🔗
pop (): T | undefined
🔗
pop (amount: number): Collection<T>

Removes given amount of items from the end of the collection and returns them as a new collection.

🔗
reverse (): Collection<T>
🔗
slice (start?: number | undefined, end?: number | undefined): Collection<T>
🔗
slide (window: number): CollectionIterable<[Collection<T>, number]>

Returns an iterable collection which iterates over the values, returning a window of the given size.

🔗
slideWrap (window: number): CollectionIterable<[Collection<T>, number]>

Returns an iterable collection which iterates over the values, returning a window of the given size. If the end of the collection is reached, the window wraps around to the start of the collection.

🔗
splice (start: number, deleteCount?: number | undefined): Collection<T>
🔗
splice (start: number, deleteCount: number, ...items: T[]): Collection<T>
🔗
split (index?: number): [Collection<T>, Collection<T>]

Splits collection. If index is omitted, collection is split in half.

🔗
splitOnValue (val: T): Collection2D<T>

Splits collection into sub-collections on given value.

🔗
toReversed (): Collection<T>
🔗
toSorted (compareFn?: ((a: T, b: T) => number) | undefined): Collection<T>
🔗
trailing (count: number): Collection<T>

Returns given amount of entries from the end of the collection, keeping their original order.

🔗
xor (...collections: Collection<T>[]): Collection<T>

Returns collection with items that are not in any other collection. (reverse of intersection)