import { MapEntry } from '../Types'; import Optional from './Optional'; type Predicate> = (value: V, key: K, collection: C) => boolean; type Reducer, U> = (accumulator: U, value: V, key: K, collection: C) => U; type Transformer, U> = (value: V, key: K, collection: C) => U; export default class Collection extends Map { /** * Removes the key and value from the map. * @param key - The key of the element to remove. * @returns An Optional containing the removed {key, value}, or empty if not found. */ remove: (key: K) => Optional>; /** * Provides a human-readable string representation. */ toString: () => string; /** * Converts the map to an array of {key, value} objects. */ toArray: () => MapEntry[]; /** * Returns the number of entries in the Collection. */ count: () => number; /** * Returns true if the key does not exist in the map. */ missing: (key: K) => boolean; /** * Converts the Collection to a JSON string. */ toJSONString: () => string; /** * Checks if the map contains a specific value. */ contains: (value: V) => boolean; /** * Merges entries from another map into this one. */ merge: (map: Map) => void; /** * Filters the collection based on a predicate. * Returns a new Collection with entries that satisfy the predicate. */ filter: (predicate: Predicate) => Collection; /** * Transforms the collection values and returns a new Collection with the transformed values. * Keys remain the same. */ mapValues: (transformFn: Transformer) => Collection; /** * Maps the collection to an array of values based on a callback function. * Returns an array of transformed values. */ mapArray: (callback: Transformer) => U[]; /** * Reduces the collection into a single value. */ reduce: (reducer: Reducer, initialValue: U) => U; /** * Checks if all entries satisfy the predicate. */ every: (predicate: Predicate) => boolean; /** * Checks if any entry satisfies the predicate. */ some: (predicate: Predicate) => boolean; /** * Finds the first entry that satisfies the predicate. * Returns an Optional containing [key, value] if found, otherwise empty. */ find: (predicate: Predicate) => Optional<[K, V]>; /** * Returns the value as an Optional. */ getOptional: (key: K) => Optional; /** * Finds the key associated with the given value. * Returns an Optional containing the key if found, otherwise empty. */ keyOf: (value: V) => Optional; } export {};