Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/harmony/src/utils/collection.ts>Collection

An easy to use Discord API Library for Deno.
Go to Latest
class Collection
extends Map<K, V>
import { Collection } from "https://deno.land/x/harmony@v2.6.0/src/utils/collection.ts";

Enhanced Map with various utility functions

Type Parameters

optional
K = string
optional
V = any

Methods

array(): V[]

Get Array of values in Collection

every(callback: (value: V, key: K) => boolean): boolean

Check if every value/key in Collection satisfies callback

filter(callback: (value: V, key: K) => boolean): Collection<K, V>

Filter out the Collection using callback

find(callback: (value: V, key: K) => boolean): V | undefined

Find a value from Collection using callback

first(): V | undefined

Get first value(s) in Collection

first(amount: number): V[]
last(): V | undefined

Get last value(s) in Collection

last(amount: number): V[]
map<T>(callback: (value: V, key: K) => T): T[]

Map the collection

Get random value(s) from Collection

random(amount: number): V[]
reduce<T>(callback: (
accumulator: T,
value: V,
key: K,
) => T
, initialValue?: T
): T

Reduce the Collection to a single value

set(key: K, value: V): this

Set a key to value in Collection

some(callback: (value: V, key: K) => boolean): boolean

Check if any of the values/keys in Collection satisfies callback

toObject(): { [name: string]: V; }

Convert Collection to an object

Static Methods

fromObject<V>(object: { [key: string]: V; }): Collection<string, V>

Create a Collection from an Object