HashMap overview
Added in v2.0.0
Table of contents
- constructors
- elements
- filtering
- folding
- getter
- getters
- mapping
- models
- refinements
- sequencing
- symbol
- traversing
- unsafe
- utils
constructors
empty
Creates a new HashMap
.
Signature
export declare const empty: <K = never, V = never>() => HashMap<K, V>
Added in v2.0.0
fromIterable
Creates a new HashMap
from an iterable collection of key/value pairs.
Signature
export declare const fromIterable: <K, V>(entries: Iterable<readonly [K, V]>) => HashMap<K, V>
Added in v2.0.0
make
Constructs a new HashMap
from an array of key/value pairs.
Signature
export declare const make: <Entries extends ReadonlyArray<readonly [any, any]>>(
...entries: Entries
) => HashMap<
Entries[number] extends readonly [infer K, any] ? K : never,
Entries[number] extends readonly [any, infer V] ? V : never
>
Added in v2.0.0
elements
findFirst
Returns the first element that satisfies the specified predicate, or None
if no such element exists.
Signature
export declare const findFirst: {
<K, A, B extends A>(predicate: (a: NoInfer<A>, k: K) => a is B): (self: HashMap<K, A>) => Option<[K, B]>
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => Option<[K, A]>
<K, A, B extends A>(self: HashMap<K, A>, predicate: (a: A, k: K) => a is B): Option<[K, B]>
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): Option<[K, A]>
}
Added in v2.0.0
get
Safely lookup the value for the specified key in the HashMap
using the internal hashing function.
Signature
export declare const get: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => Option<V>
<K, V, K1>(self: HashMap<K, V>, key: K1): Option<V>
}
Added in v2.0.0
getHash
Lookup the value for the specified key in the HashMap
using a custom hash.
Signature
export declare const getHash: {
<K1>(key: K1, hash: number): <K, V>(self: HashMap<K, V>) => Option<V>
<K, V, K1>(self: HashMap<K, V>, key: K1, hash: number): Option<V>
}
Added in v2.0.0
has
Checks if the specified key has an entry in the HashMap
.
Signature
export declare const has: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => boolean
<K, V, K1>(self: HashMap<K, V>, key: K1): boolean
}
Added in v2.0.0
hasHash
Checks if the specified key has an entry in the HashMap
using a custom hash.
Signature
export declare const hasHash: {
<K1>(key: K1, hash: number): <K, V>(self: HashMap<K, V>) => boolean
<K, V, K1>(self: HashMap<K, V>, key: K1, hash: number): boolean
}
Added in v2.0.0
isEmpty
Checks if the HashMap
contains any entries.
Signature
export declare const isEmpty: <K, V>(self: HashMap<K, V>) => boolean
Added in v2.0.0
some
Checks if any entry in a hashmap meets a specific condition.
Signature
export declare const some: {
<K, A>(predicate: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => boolean
<K, A>(self: HashMap<K, A>, predicate: (a: A, k: K) => boolean): boolean
}
Added in v3.13.0
filtering
compact
Filters out None
values from a HashMap
of Options
s.
Signature
export declare const compact: <K, A>(self: HashMap<K, Option<A>>) => HashMap<K, A>
Added in v2.0.0
filter
Filters entries out of a HashMap
using the specified predicate.
Signature
export declare const filter: {
<K, A, B extends A>(f: (a: NoInfer<A>, k: K) => a is B): (self: HashMap<K, A>) => HashMap<K, B>
<K, A>(f: (a: NoInfer<A>, k: K) => boolean): (self: HashMap<K, A>) => HashMap<K, A>
<K, A, B extends A>(self: HashMap<K, A>, f: (a: A, k: K) => a is B): HashMap<K, B>
<K, A>(self: HashMap<K, A>, f: (a: A, k: K) => boolean): HashMap<K, A>
}
Added in v2.0.0
filterMap
Maps over the entries of the HashMap
using the specified partial function and filters out None
values.
Signature
export declare const filterMap: {
<A, K, B>(f: (value: A, key: K) => Option<B>): (self: HashMap<K, A>) => HashMap<K, B>
<K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => Option<B>): HashMap<K, B>
}
Added in v2.0.0
folding
reduce
Reduces the specified state over the entries of the HashMap
.
Signature
export declare const reduce: {
<Z, V, K>(zero: Z, f: (accumulator: Z, value: V, key: K) => Z): (self: HashMap<K, V>) => Z
<K, V, Z>(self: HashMap<K, V>, zero: Z, f: (accumulator: Z, value: V, key: K) => Z): Z
}
Added in v2.0.0
getter
keySet
Returns a HashSet
of keys within the HashMap
.
Signature
export declare const keySet: <K, V>(self: HashMap<K, V>) => HashSet<K>
Added in v2.0.0
getters
entries
Returns an IterableIterator
of the entries within the HashMap
.
Signature
export declare const entries: <K, V>(self: HashMap<K, V>) => IterableIterator<[K, V]>
Added in v2.0.0
keys
Returns an IterableIterator
of the keys within the HashMap
.
Signature
export declare const keys: <K, V>(self: HashMap<K, V>) => IterableIterator<K>
Added in v2.0.0
size
Returns the number of entries within the HashMap
.
Signature
export declare const size: <K, V>(self: HashMap<K, V>) => number
Added in v2.0.0
toEntries
Returns an Array<[K, V]>
of the entries within the HashMap
.
Signature
export declare const toEntries: <K, V>(self: HashMap<K, V>) => Array<[K, V]>
Added in v2.0.0
toValues
Returns an Array
of the values within the HashMap
.
Signature
export declare const toValues: <K, V>(self: HashMap<K, V>) => Array<V>
Added in v3.13.0
values
Returns an IterableIterator
of the values within the HashMap
.
Signature
export declare const values: <K, V>(self: HashMap<K, V>) => IterableIterator<V>
Added in v2.0.0
mapping
map
Maps over the entries of the HashMap
using the specified function.
Signature
export declare const map: {
<A, V, K>(f: (value: V, key: K) => A): (self: HashMap<K, V>) => HashMap<K, A>
<K, V, A>(self: HashMap<K, V>, f: (value: V, key: K) => A): HashMap<K, A>
}
Added in v2.0.0
models
HashMap (interface)
Signature
export interface HashMap<out Key, out Value> extends Iterable<[Key, Value]>, Equal, Pipeable, Inspectable {
readonly [TypeId]: TypeId
}
Added in v2.0.0
refinements
isHashMap
Signature
export declare const isHashMap: {
<K, V>(u: Iterable<readonly [K, V]>): u is HashMap<K, V>
(u: unknown): u is HashMap<unknown, unknown>
}
Added in v2.0.0
sequencing
flatMap
Chains over the entries of the HashMap
using the specified function.
NOTE: the hash and equal of both maps have to be the same.
Signature
export declare const flatMap: {
<A, K, B>(f: (value: A, key: K) => HashMap<K, B>): (self: HashMap<K, A>) => HashMap<K, B>
<K, A, B>(self: HashMap<K, A>, f: (value: A, key: K) => HashMap<K, B>): HashMap<K, B>
}
Added in v2.0.0
symbol
TypeId (type alias)
Signature
export type TypeId = typeof TypeId
Added in v2.0.0
traversing
forEach
Applies the specified function to the entries of the HashMap
.
Signature
export declare const forEach: {
<V, K>(f: (value: V, key: K) => void): (self: HashMap<K, V>) => void
<V, K>(self: HashMap<K, V>, f: (value: V, key: K) => void): void
}
Added in v2.0.0
unsafe
unsafeGet
Unsafely lookup the value for the specified key in the HashMap
using the internal hashing function.
Signature
export declare const unsafeGet: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => V
<K, V, K1>(self: HashMap<K, V>, key: K1): V
}
Added in v2.0.0
utils
HashMap (namespace)
Added in v2.0.0
Entry (type alias)
This type-level utility extracts the entry type [K, V]
from a HashMap<K, V>
type.
Signature
export type Entry<T extends HashMap<any, any>> = [Key<T>, Value<T>]
Example
import { HashMap } from "effect"
declare const hm: HashMap.HashMap<string, number>
// $ExpectType [string, number]
type V = HashMap.HashMap.Entry<typeof hm>
Added in v3.9.0
Key (type alias)
This type-level utility extracts the key type K
from a HashMap<K, V>
type.
Signature
export type Key<T extends HashMap<any, any>> = [T] extends [HashMap<infer _K, infer _V>] ? _K : never
Example
import { HashMap } from "effect"
declare const hm: HashMap.HashMap<string, number>
// $ExpectType string
type K = HashMap.HashMap.Key<typeof hm>
Added in v2.0.0
UpdateFn (type alias)
Signature
export type UpdateFn<V> = (option: Option<V>) => Option<V>
Added in v2.0.0
Value (type alias)
This type-level utility extracts the value type V
from a HashMap<K, V>
type.
Signature
export type Value<T extends HashMap<any, any>> = [T] extends [HashMap<infer _K, infer _V>] ? _V : never
Example
import { HashMap } from "effect"
declare const hm: HashMap.HashMap<string, number>
// $ExpectType number
type V = HashMap.HashMap.Value<typeof hm>
Added in v2.0.0
beginMutation
Marks the HashMap
as mutable.
Signature
export declare const beginMutation: <K, V>(self: HashMap<K, V>) => HashMap<K, V>
Added in v2.0.0
endMutation
Marks the HashMap
as immutable.
Signature
export declare const endMutation: <K, V>(self: HashMap<K, V>) => HashMap<K, V>
Added in v2.0.0
modify
Updates the value of the specified key within the HashMap
if it exists.
Signature
export declare const modify: {
<K, V>(key: K, f: (v: V) => V): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, f: (v: V) => V): HashMap<K, V>
}
Added in v2.0.0
modifyAt
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.
Signature
export declare const modifyAt: {
<K, V>(key: K, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, f: HashMap.UpdateFn<V>): HashMap<K, V>
}
Added in v2.0.0
modifyHash
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
.
Signature
export declare const modifyHash: {
<K, V>(key: K, hash: number, f: HashMap.UpdateFn<V>): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, hash: number, f: HashMap.UpdateFn<V>): HashMap<K, V>
}
Added in v2.0.0
mutate
Mutates the HashMap
within the context of the provided function.
Signature
export declare const mutate: {
<K, V>(f: (self: HashMap<K, V>) => void): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, f: (self: HashMap<K, V>) => void): HashMap<K, V>
}
Added in v2.0.0
remove
Remove the entry for the specified key in the HashMap
using the internal hashing function.
Signature
export declare const remove: {
<K>(key: K): <V>(self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K): HashMap<K, V>
}
Added in v2.0.0
removeMany
Removes all entries in the HashMap
which have the specified keys.
Signature
export declare const removeMany: {
<K>(keys: Iterable<K>): <V>(self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, keys: Iterable<K>): HashMap<K, V>
}
Added in v2.0.0
set
Sets the specified key to the specified value using the internal hashing function.
Signature
export declare const set: {
<K, V>(key: K, value: V): (self: HashMap<K, V>) => HashMap<K, V>
<K, V>(self: HashMap<K, V>, key: K, value: V): HashMap<K, V>
}
Added in v2.0.0
union
Performs a union of this HashMap
and that HashMap
.
Signature
export declare const union: {
<K1, V1>(that: HashMap<K1, V1>): <K0, V0>(self: HashMap<K0, V0>) => HashMap<K1 | K0, V1 | V0>
<K0, V0, K1, V1>(self: HashMap<K0, V0>, that: HashMap<K1, V1>): HashMap<K0 | K1, V0 | V1>
}
Added in v2.0.0