Collection is a wrapper around Array with utility functions for common operations.
Collection
()
T
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.
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
(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.
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)