Skip to content

Commit 6565916

Browse files
authoredFeb 16, 2024··
fix Hash implemention for Option.none (#2165)
1 parent ca2b411 commit 6565916

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
 

‎.changeset/lucky-mirrors-know.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
fix Hash implemention for Option.none

‎packages/effect/src/internal/option.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ const SomeProto = Object.assign(Object.create(CommonProto), {
4242
}
4343
})
4444

45+
const NoneHash = Hash.hash("None")
4546
const NoneProto = Object.assign(Object.create(CommonProto), {
4647
_tag: "None",
4748
_op: "None",
4849
[Equal.symbol]<A>(this: Option.None<A>, that: unknown): boolean {
4950
return isOption(that) && isNone(that)
5051
},
5152
[Hash.symbol]<A>(this: Option.None<A>) {
52-
return Hash.combine(Hash.hash(this._tag))
53+
return NoneHash
5354
},
5455
toJSON<A>(this: Option.None<A>) {
5556
return {

‎packages/effect/test/Option.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as Util from "effect-test/util"
22
import * as Chunk from "effect/Chunk"
33
import * as E from "effect/Either"
4+
import * as Equal from "effect/Equal"
45
import { pipe } from "effect/Function"
6+
import * as Hash from "effect/Hash"
57
import * as N from "effect/Number"
68
import * as _ from "effect/Option"
79
import * as S from "effect/String"
@@ -87,6 +89,18 @@ describe("Option", () => {
8789
expect(inspect(_.some(1))).toEqual(inspect({ _id: "Option", _tag: "Some", value: 1 }))
8890
})
8991

92+
it("Equal", () => {
93+
expect(Equal.equals(_.some(1), _.some(1))).toEqual(true)
94+
expect(Equal.equals(_.some(1), _.some(2))).toEqual(false)
95+
expect(Equal.equals(_.none(), _.none())).toEqual(true)
96+
})
97+
98+
it("Hash", () => {
99+
expect(Hash.hash(_.some(1))).toEqual(Hash.hash(_.some(1)))
100+
expect(Hash.hash(_.some(1)) === Hash.hash(_.some(2))).toEqual(false)
101+
expect(Hash.hash(_.none())).toEqual(Hash.hash(_.none()))
102+
})
103+
90104
it("getRight", () => {
91105
expect(_.getRight(E.right(1))).toEqual(_.some(1))
92106
expect(_.getRight(E.left("a"))).toEqual(_.none())

0 commit comments

Comments
 (0)
Please sign in to comment.