Skip to content

Commit 530394a

Browse files
rachel-barrettRachel Barrett
andauthored
1962 fix option get ord compare when comparing equality of options (#1963)
* Add test that currently fails * fix to option getOrd compare function to return 0 for two none values that are not referentially equal --------- Co-authored-by: Rachel Barrett <rachel@flyp.co>
1 parent e91bde1 commit 530394a

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

src/Option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export const getEq = <A>(E: Eq<A>): Eq<Option<A>> => ({
297297
*/
298298
export const getOrd = <A>(O: Ord<A>): Ord<Option<A>> => ({
299299
equals: getEq(O).equals,
300-
compare: (x, y) => (x === y ? 0 : isSome(x) ? (isSome(y) ? O.compare(x.value, y.value) : 1) : -1)
300+
compare: (x, y) => (isSome(x) ? (isSome(y) ? O.compare(x.value, y.value) : 1) : isSome(y) ? -1 : 0)
301301
})
302302

303303
/**

test/Option.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ describe('Option', () => {
297297
it('getOrd', () => {
298298
const OS = _.getOrd(S.Ord)
299299
U.deepStrictEqual(OS.compare(_.none, _.none), 0)
300+
U.deepStrictEqual(OS.compare(_.none, { _tag: 'None' }), 0)
300301
U.deepStrictEqual(OS.compare(_.some('a'), _.none), 1)
301302
U.deepStrictEqual(OS.compare(_.none, _.some('a')), -1)
302303
U.deepStrictEqual(OS.compare(_.some('a'), _.some('a')), 0)

0 commit comments

Comments
 (0)