Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/famous-rockets-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"effect": patch
---

- The `HashMap.has/get` family has become more type-safe.
- Fix the related type errors in TestAnnotationsMap.ts.
20 changes: 10 additions & 10 deletions packages/effect/src/HashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ export const isEmpty: <K, V>(self: HashMap<K, V>) => boolean = HM.isEmpty
* @category elements
*/
export const get: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => Option<V>
<K, V, K1>(self: HashMap<K, V>, key: K1): Option<V>
<K1 extends K, K>(key: K1): <V>(self: HashMap<K, V>) => Option<V>
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): Option<V>
} = HM.get

/**
Expand All @@ -155,8 +155,8 @@ export const get: {
* @category elements
*/
export 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>
<K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => Option<V>
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): Option<V>
} = HM.getHash

/**
Expand All @@ -167,8 +167,8 @@ export const getHash: {
* @category unsafe
*/
export const unsafeGet: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => V
<K, V, K1>(self: HashMap<K, V>, key: K1): V
<K1 extends K, K>(key: K1): <V>(self: HashMap<K, V>) => V
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): V
} = HM.unsafeGet

/**
Expand All @@ -178,8 +178,8 @@ export const unsafeGet: {
* @category elements
*/
export const has: {
<K1>(key: K1): <K, V>(self: HashMap<K, V>) => boolean
<K, V, K1>(self: HashMap<K, V>, key: K1): boolean
<K1 extends K, K>(key: K1): <K, V>(self: HashMap<K, V>) => boolean
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1): boolean
} = HM.has

/**
Expand All @@ -190,8 +190,8 @@ export const has: {
* @category elements
*/
export 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
<K1 extends K, K>(key: K1, hash: number): <V>(self: HashMap<K, V>) => boolean
<K1 extends K, K, V>(self: HashMap<K, V>, key: K1, hash: number): boolean
} = HM.hasHash

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/effect/src/TestAnnotationMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const update = dual<
<A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>, f: (value: A) => A) => TestAnnotationMap
>(3, <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>, f: (value: A) => A) => {
let value = key.initial
if (HashMap.has(self.map, key.identifier)) {
value = HashMap.unsafeGet(self.map, key.identifier) as A
if (HashMap.has(self.map, key)) {
value = HashMap.unsafeGet(self.map, key) as A
}
return overwrite(self, key, f(value))
})
Expand All @@ -83,8 +83,8 @@ export const get = dual<
<A>(key: TestAnnotation.TestAnnotation<A>) => (self: TestAnnotationMap) => A,
<A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>) => A
>(2, <A>(self: TestAnnotationMap, key: TestAnnotation.TestAnnotation<A>) => {
if (HashMap.has(self.map, key.identifier)) {
return HashMap.unsafeGet(self.map, key.identifier) as A
if (HashMap.has(self.map, key)) {
return HashMap.unsafeGet(self.map, key) as A
}
return key.initial
})
Expand Down
22 changes: 11 additions & 11 deletions packages/effect/src/internal/hashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ export const isEmpty = <K, V>(self: HM.HashMap<K, V>): boolean =>

/** @internal */
export const get = Dual.dual<
<K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => Option.Option<V>,
<K, V, K1>(self: HM.HashMap<K, V>, key: K1) => Option.Option<V>
<K1 extends K, K>(key: K1) => <V>(self: HM.HashMap<K, V>) => Option.Option<V>,
<K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1) => Option.Option<V>
>(2, (self, key) => getHash(self, key, Hash.hash(key)))

/** @internal */
export const getHash = Dual.dual<
<K1>(key: K1, hash: number) => <K, V>(self: HM.HashMap<K, V>) => Option.Option<V>,
<K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => Option.Option<V>
>(3, <K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => {
<K1 extends K, K>(key: K1, hash: number) => <V>(self: HM.HashMap<K, V>) => Option.Option<V>,
<K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1, hash: number) => Option.Option<V>
>(3, <K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1, hash: number) => {
let node = (self as HashMapImpl<K, V>)._root
let shift = 0

Expand Down Expand Up @@ -265,8 +265,8 @@ export const getHash = Dual.dual<

/** @internal */
export const unsafeGet = Dual.dual<
<K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => V,
<K, V, K1>(self: HM.HashMap<K, V>, key: K1) => V
<K1 extends K, K>(key: K1) => <V>(self: HM.HashMap<K, V>) => V,
<K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1) => V
>(2, (self, key) => {
const element = getHash(self, key, Hash.hash(key))
if (Option.isNone(element)) {
Expand All @@ -277,14 +277,14 @@ export const unsafeGet = Dual.dual<

/** @internal */
export const has = Dual.dual<
<K1>(key: K1) => <K, V>(self: HM.HashMap<K, V>) => boolean,
<K, V, K1>(self: HM.HashMap<K, V>, key: K1) => boolean
<K1 extends K, K>(key: K1) => <V>(self: HM.HashMap<K, V>) => boolean,
<K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1) => boolean
>(2, (self, key) => Option.isSome(getHash(self, key, Hash.hash(key))))

/** @internal */
export const hasHash = Dual.dual<
<K1>(key: K1, hash: number) => <K, V>(self: HM.HashMap<K, V>) => boolean,
<K, V, K1>(self: HM.HashMap<K, V>, key: K1, hash: number) => boolean
<K1 extends K, K>(key: K1, hash: number) => <V>(self: HM.HashMap<K, V>) => boolean,
<K, V, K1 extends K>(self: HM.HashMap<K, V>, key: K1, hash: number) => boolean
>(3, (self, key, hash) => Option.isSome(getHash(self, key, hash)))

/** @internal */
Expand Down