From 7937019b91966a0979f9364a41ffba5ab8116a0b Mon Sep 17 00:00:00 2001 From: gcanti Date: Tue, 4 Feb 2020 19:26:47 +0100 Subject: [PATCH] add eqStrict, closes #965 --- CHANGELOG.md | 2 ++ docs/modules/Eq.ts.md | 17 +++++++++++++++-- src/Eq.ts | 13 +++++++++++-- test/Eq.ts | 7 ++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c849910c..80ce2808b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ high state of flux, you're at risk of it changing without notice. - add `ReadonlyMap` module (@gcanti) - add `ReadonlyRecord` module (@gcanti) - add `ReadonlyTuple` module (@gcanti) + - `Eq` + - add `eqStrict`, closes #965 (@gcanti) - `NonEmptyArray` - add `fold` (@vicrac) - `Semigroup` diff --git a/docs/modules/Eq.ts.md b/docs/modules/Eq.ts.md index f28ae2db4..3a6229be0 100644 --- a/docs/modules/Eq.ts.md +++ b/docs/modules/Eq.ts.md @@ -28,11 +28,12 @@ Added in v2.0.0 - [eqBoolean](#eqboolean) - [eqDate](#eqdate) - [eqNumber](#eqnumber) +- [eqStrict](#eqstrict) - [eqString](#eqstring) - [fromEquals](#fromequals) - [getStructEq](#getstructeq) - [getTupleEq](#gettupleeq) -- [strictEqual](#strictequal) +- [~~strictEqual~~](#strictequal) --- @@ -118,6 +119,16 @@ export const eqNumber: Eq = ... Added in v2.0.0 +# eqStrict + +**Signature** + +```ts +export const eqStrict: Eq = ... +``` + +Added in v2.5.0 + # eqString **Signature** @@ -174,7 +185,9 @@ assert.strictEqual(E.equals(['a', 1, true], ['a', 1, false]), false) Added in v2.0.0 -# strictEqual +# ~~strictEqual~~ + +Use `eqStrict` instead **Signature** diff --git a/src/Eq.ts b/src/Eq.ts index 12fbe807f..5bace69ee 100644 --- a/src/Eq.ts +++ b/src/Eq.ts @@ -46,14 +46,23 @@ export function fromEquals(equals: (x: A, y: A) => boolean): Eq { } /** + * @since 2.5.0 + */ +export const eqStrict: Eq = { + // tslint:disable-next-line: deprecation + equals: strictEqual +} + +/** + * Use `eqStrict` instead + * * @since 2.0.0 + * @deprecated */ export function strictEqual(a: A, b: A): boolean { return a === b } -const eqStrict = { equals: strictEqual } - /** * @since 2.0.0 */ diff --git a/test/Eq.ts b/test/Eq.ts index 85c731cd9..10df20463 100644 --- a/test/Eq.ts +++ b/test/Eq.ts @@ -1,5 +1,5 @@ import * as assert from 'assert' -import { eq, eqDate, eqNumber, eqString, fromEquals, getTupleEq, eqBoolean, getStructEq } from '../src/Eq' +import { eq, eqDate, eqNumber, eqString, fromEquals, getTupleEq, eqBoolean, getStructEq, eqStrict } from '../src/Eq' describe('Eq', () => { it('getTupleEq', () => { @@ -54,4 +54,9 @@ describe('Eq', () => { assert.deepStrictEqual(S.equals({ name: 'a', age: 1 }, { name: 'a', age: 2 }), false) assert.deepStrictEqual(S.equals({ name: 'a', age: 1 }, { name: 'b', age: 1 }), false) }) + + it('eqStrict', () => { + assert.deepStrictEqual(eqStrict.equals(1, 1), true) + assert.deepStrictEqual(eqStrict.equals(1, 'a'), false) + }) })