/** * The `Eq` type class represents types which support decidable equality. * * Instances must satisfy the following laws: * * 1. Reflexivity: `E.equals(a, a) === true` * 2. Symmetry: `E.equals(a, b) === E.equals(b, a)` * 3. Transitivity: if `E.equals(a, b) === true` and `E.equals(b, c) === true`, then `E.equals(a, c) === true` * * @since 2.0.0 */ import { Contravariant1 } from './Contravariant' import { Monoid } from './Monoid' import { ReadonlyRecord } from './ReadonlyRecord' import { Semigroup } from './Semigroup' /** * @category model * @since 2.0.0 */ export interface Eq { readonly equals: (x: A, y: A) => boolean } /** * @category constructors * @since 2.0.0 */ export declare const fromEquals: (equals: (x: A, y: A) => boolean) => Eq /** * @since 2.10.0 */ export declare const struct: (eqs: { [K in keyof A]: Eq }) => Eq<{ readonly [K_1 in keyof A]: A[K_1] }> /** * Given a tuple of `Eq`s returns a `Eq` for the tuple * * @example * import { tuple } from 'fp-ts/Eq' * import * as S from 'fp-ts/string' * import * as N from 'fp-ts/number' * import * as B from 'fp-ts/boolean' * * const E = tuple(S.Eq, N.Eq, B.Eq) * assert.strictEqual(E.equals(['a', 1, true], ['a', 1, true]), true) * assert.strictEqual(E.equals(['a', 1, true], ['b', 1, true]), false) * assert.strictEqual(E.equals(['a', 1, true], ['a', 2, true]), false) * assert.strictEqual(E.equals(['a', 1, true], ['a', 1, false]), false) * * @since 2.10.0 */ export declare const tuple: (...eqs: { [K in keyof A]: Eq }) => Eq> /** * A typical use case for `contramap` would be like, given some `User` type, to construct an `Eq`. * * We can do so with a function from `User -> X` where `X` is some value that we know how to compare * for equality (meaning we have an `Eq`) * * For example, given the following `User` type, we want to construct an `Eq` that just looks at the `key` field * for each user (since it's known to be unique). * * If we have a way of comparing `UUID`s for equality (`eqUUID: Eq`) and we know how to go from `User -> UUID`, * using `contramap` we can do this * * @example * import { contramap, Eq } from 'fp-ts/Eq' * import { pipe } from 'fp-ts/function' * import * as S from 'fp-ts/string' * * type UUID = string * * interface User { * readonly key: UUID * readonly firstName: string * readonly lastName: string * } * * const eqUUID: Eq = S.Eq * * const eqUserByKey: Eq = pipe( * eqUUID, * contramap((user) => user.key) * ) * * assert.deepStrictEqual( * eqUserByKey.equals( * { key: 'k1', firstName: 'a1', lastName: 'b1' }, * { key: 'k2', firstName: 'a1', lastName: 'b1' } * ), * false * ) * assert.deepStrictEqual( * eqUserByKey.equals( * { key: 'k1', firstName: 'a1', lastName: 'b1' }, * { key: 'k1', firstName: 'a2', lastName: 'b1' } * ), * true * ) * * @since 2.0.0 */ export declare const contramap: (f: (b: B) => A) => (fa: Eq) => Eq /** * @category type lambdas * @since 2.0.0 */ export declare const URI = 'Eq' /** * @category type lambdas * @since 2.0.0 */ export declare type URI = typeof URI declare module './HKT' { interface URItoKind { readonly [URI]: Eq } } /** * @category instances * @since 2.5.0 */ export declare const eqStrict: Eq /** * @category instances * @since 2.10.0 */ export declare const getSemigroup: () => Semigroup> /** * @category instances * @since 2.6.0 */ export declare const getMonoid: () => Monoid> /** * @category instances * @since 2.7.0 */ export declare const Contravariant: Contravariant1 /** * Use [`tuple`](#tuple) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getTupleEq: >>( ...eqs: T ) => Eq<{ [K in keyof T]: T[K] extends Eq ? A : never }> /** * Use [`struct`](#struct) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const getStructEq: >(eqs: { [K in keyof O]: Eq }) => Eq /** * Use [`eqStrict`](#eqstrict) instead * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const strictEqual: (a: A, b: A) => boolean /** * This instance is deprecated, use small, specific instances instead. * For example if a function needs a `Contravariant` instance, pass `E.Contravariant` instead of `E.eq` * (where `E` is from `import E from 'fp-ts/Eq'`) * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const eq: Contravariant1 /** * Use [`Eq`](./boolean.ts.html#eq) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const eqBoolean: Eq /** * Use [`Eq`](./string.ts.html#eq) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const eqString: Eq /** * Use [`Eq`](./number.ts.html#eq) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const eqNumber: Eq /** * Use [`Eq`](./Date.ts.html#eq) instead. * * @category zone of death * @since 2.0.0 * @deprecated */ export declare const eqDate: Eq