/** * @since 1.0.0 */ import type { Equal } from "@effect/data/Equal" import type { HashSet } from "@effect/data/HashSet" import type { Inspectable } from "@effect/data/Inspectable" import * as HM from "@effect/data/internal/HashMap" import * as _keySet from "@effect/data/internal/HashMap/keySet" import type { Option } from "@effect/data/Option" import type { Pipeable } from "@effect/data/Pipeable" const TypeId: unique symbol = HM.HashMapTypeId as TypeId /** * @since 1.0.0 * @category symbol */ export type TypeId = typeof TypeId /** * @since 1.0.0 * @category models */ export interface HashMap extends Iterable<[Key, Value]>, Equal, Pipeable, Inspectable { [TypeId]: TypeId } /** * @since 1.0.0 */ export declare namespace HashMap { /** * @since 1.0.0 * @category models */ export type UpdateFn = (option: Option) => Option } /** * @since 1.0.0 * @category refinements */ export const isHashMap: { (u: Iterable): u is HashMap (u: unknown): u is HashMap } = HM.isHashMap /** * Creates a new `HashMap`. * * @since 1.0.0 * @category constructors */ export const empty: () => HashMap = HM.empty /** * Constructs a new `HashMap` from an array of key/value pairs. * * @since 1.0.0 * @category constructors */ export const make: >( ...entries: Entries ) => HashMap< Entries[number] extends readonly [infer K, any] ? K : never, Entries[number] extends readonly [any, infer V] ? V : never > = HM.make /** * Constructs a new `HashMap` from an iterable of key/value pairs. * * @since 1.0.0 * @category constructors */ export const fromIterable: (entries: Iterable) => HashMap = HM.fromIterable /** * Checks if the `HashMap` contains any entries. * * @since 1.0.0 * @category elements */ export const isEmpty: (self: HashMap) => boolean = HM.isEmpty /** * Safely lookup the value for the specified key in the `HashMap` using the * internal hashing function. * * @since 1.0.0 * @category elements */ export const get: { (key: K1): (self: HashMap) => Option (self: HashMap, key: K1): Option } = HM.get /** * Lookup the value for the specified key in the `HashMap` using a custom hash. * * @since 1.0.0 * @category elements */ export const getHash: { (key: K1, hash: number): (self: HashMap) => Option (self: HashMap, key: K1, hash: number): Option } = HM.getHash /** * Unsafely lookup the value for the specified key in the `HashMap` using the * internal hashing function. * * @since 1.0.0 * @category unsafe */ export const unsafeGet: { (key: K1): (self: HashMap) => V (self: HashMap, key: K1): V } = HM.unsafeGet /** * Checks if the specified key has an entry in the `HashMap`. * * @since 1.0.0 * @category elements */ export const has: { (key: K1): (self: HashMap) => boolean (self: HashMap, key: K1): boolean } = HM.has /** * Checks if the specified key has an entry in the `HashMap` using a custom * hash. * * @since 1.0.0 * @category elements */ export const hasHash: { (key: K1, hash: number): (self: HashMap) => boolean (self: HashMap, key: K1, hash: number): boolean } = HM.hasHash /** * Sets the specified key to the specified value using the internal hashing * function. * * @since 1.0.0 */ export const set: { (key: K, value: V): (self: HashMap) => HashMap (self: HashMap, key: K, value: V): HashMap } = HM.set /** * Returns an `IterableIterator` of the keys within the `HashMap`. * * @since 1.0.0 * @category getters */ export const keys: (self: HashMap) => IterableIterator = HM.keys /** * Returns a `HashSet` of keys within the `HashMap`. * * @since 1.0.0 * @category getter */ export const keySet: (self: HashMap) => HashSet = _keySet.keySet /** * Returns an `IterableIterator` of the values within the `HashMap`. * * @since 1.0.0 * @category getters */ export const values: (self: HashMap) => IterableIterator = HM.values /** * Returns the number of entries within the `HashMap`. * * @since 1.0.0 * @category getters */ export const size: (self: HashMap) => number = HM.size /** * Marks the `HashMap` as mutable. * * @since 1.0.0 */ export const beginMutation: (self: HashMap) => HashMap = HM.beginMutation /** * Marks the `HashMap` as immutable. * * @since 1.0.0 */ export const endMutation: (self: HashMap) => HashMap = HM.endMutation /** * Mutates the `HashMap` within the context of the provided function. * * @since 1.0.0 */ export const mutate: { (f: (self: HashMap) => void): (self: HashMap) => HashMap (self: HashMap, f: (self: HashMap) => void): HashMap } = HM.mutate /** * Set or remove the specified key in the `HashMap` using the specified * update function. The value of the specified key will be computed using the * provided hash. * * The update function will be invoked with the current value of the key if it * exists, or `None` if no such value exists. * * @since 1.0.0 */ export const modifyAt: { (key: K, f: HashMap.UpdateFn): (self: HashMap) => HashMap (self: HashMap, key: K, f: HashMap.UpdateFn): HashMap } = HM.modifyAt /** * Alter the value of the specified key in the `HashMap` using the specified * update function. The value of the specified key will be computed using the * provided hash. * * The update function will be invoked with the current value of the key if it * exists, or `None` if no such value exists. * * This function will always either update or insert a value into the `HashMap`. * * @since 1.0.0 */ export const modifyHash: { (key: K, hash: number, f: HashMap.UpdateFn): (self: HashMap) => HashMap (self: HashMap, key: K, hash: number, f: HashMap.UpdateFn): HashMap } = HM.modifyHash /** * Updates the value of the specified key within the `HashMap` if it exists. * * @since 1.0.0 */ export const modify: { (key: K, f: (v: V) => V): (self: HashMap) => HashMap (self: HashMap, key: K, f: (v: V) => V): HashMap } = HM.modify /** * Performs a union of this `HashMap` and that `HashMap`. * * @since 1.0.0 */ export const union: { (that: HashMap): (self: HashMap) => HashMap (self: HashMap, that: HashMap): HashMap } = HM.union /** * Remove the entry for the specified key in the `HashMap` using the internal * hashing function. * * @since 1.0.0 */ export const remove: { (key: K): (self: HashMap) => HashMap (self: HashMap, key: K): HashMap } = HM.remove /** * Removes all entries in the `HashMap` which have the specified keys. * * @since 1.0.0 */ export const removeMany: { (keys: Iterable): (self: HashMap) => HashMap (self: HashMap, keys: Iterable): HashMap } = HM.removeMany /** * Maps over the entries of the `HashMap` using the specified function. * * @since 1.0.0 * @category mapping */ export const map: { (f: (value: V, key: K) => A): (self: HashMap) => HashMap (self: HashMap, f: (value: V, key: K) => A): HashMap } = HM.map /** * Chains over the entries of the `HashMap` using the specified function. * * **NOTE**: the hash and equal of both maps have to be the same. * * @since 1.0.0 * @category sequencing */ export const flatMap: { (f: (value: A, key: K) => HashMap): (self: HashMap) => HashMap (self: HashMap, f: (value: A, key: K) => HashMap): HashMap } = HM.flatMap /** * Applies the specified function to the entries of the `HashMap`. * * @since 1.0.0 * @category traversing */ export const forEach: { (f: (value: V, key: K) => void): (self: HashMap) => void (self: HashMap, f: (value: V, key: K) => void): void } = HM.forEach /** * Reduces the specified state over the entries of the `HashMap`. * * @since 1.0.0 * @category folding */ export const reduce: { (zero: Z, f: (accumulator: Z, value: V, key: K) => Z): (self: HashMap) => Z (self: HashMap, zero: Z, f: (accumulator: Z, value: V, key: K) => Z): Z } = HM.reduce /** * Filters entries out of a `HashMap` using the specified predicate. * * @since 1.0.0 * @category filtering */ export const filter: { (f: (a: A, k: K) => a is B): (self: HashMap) => HashMap (f: (a: A, k: K) => boolean): (self: HashMap) => HashMap (self: HashMap, f: (a: A, k: K) => a is B): HashMap (self: HashMap, f: (a: A, k: K) => boolean): HashMap } = HM.filter /** * Filters out `None` values from a `HashMap` of `Options`s. * * @since 1.0.0 * @category filtering */ export const compact: (self: HashMap>) => HashMap = HM.compact /** * Maps over the entries of the `HashMap` using the specified partial function * and filters out `None` values. * * @since 1.0.0 * @category filtering */ export const filterMap: { (f: (value: A, key: K) => Option): (self: HashMap) => HashMap (self: HashMap, f: (value: A, key: K) => Option): HashMap } = HM.filterMap /** * Returns the first element that satisfies the specified * predicate, or `None` if no such element exists. * * @category elements * @since 1.0.0 */ export const findFirst: { (predicate: (k: K, a: A) => boolean): (self: HashMap) => Option<[K, A]> (self: HashMap, predicate: (k: K, a: A) => boolean): Option<[K, A]> } = HM.findFirst