Skip to content

Commit

Permalink
fixes #58 Tuple2 equality is broken
Browse files Browse the repository at this point in the history
tuple2 equality was broken if the first field of the second tuple was
falsy. Bad falsy if statement :(
  • Loading branch information
emmanueltouzery committed May 27, 2022
1 parent e94488f commit d1f64d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tuple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Tuple2<T,U> implements Value {
if (<any>other === this) {
return true;
}
if (!other || !other._fst) {
if (!other || other._fst === undefined) {
return false;
}
contractTrueEquality("Tuple2.equals", this, other);
Expand Down
6 changes: 6 additions & 0 deletions tests/Tuple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ describe("Tuple2 manipulation", () => {
Option.of(Tuple2.of(1,2)).equals(Tuple2.ofArray<number,number>([1,2]))));
it("build from array works - failure", () => assert.ok(
Tuple2.ofArray([1,2,3]).isNone()));
it("gives correct equality answer even if fst is falsy", () => assert.ok(
Tuple2.of(0, "").equals(Tuple2.of(0, ""))));
it("gives correct equality answer #2", () => assert.ok(
!Tuple2.of(0, "").equals(Tuple2.of(0, "a"))));
it("gives correct equality answer #3", () => assert.ok(
!Tuple2.of(1, "").equals(Tuple2.of(0, ""))));
});

0 comments on commit d1f64d7

Please sign in to comment.