Eq overview

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

Added in v2.0.0


Table of contents


Contravariant

contramap

Signature

export declare const contramap: <A, B>(f: (b: B) => A) => (fa: Eq<A>) => Eq<B>

Added in v2.0.0

constructors

fromEquals

Signature

export declare function fromEquals<A>(equals: (x: A, y: A) => boolean): Eq<A>

Added in v2.0.0

instances

URI

Signature

export declare const URI: 'Eq'

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

contravariantEq

Signature

export declare const contravariantEq: Contravariant1<'Eq'>

Added in v2.7.0

eq

Signature

export declare const eq: Contravariant1<'Eq'>

Added in v2.0.0

eqBoolean

Signature

export declare const eqBoolean: Eq<boolean>

Added in v2.0.0

eqDate

Signature

export declare const eqDate: Eq<Date>

Added in v2.0.0

eqNumber

Signature

export declare const eqNumber: Eq<number>

Added in v2.0.0

eqStrict

Signature

export declare const eqStrict: Eq<unknown>

Added in v2.5.0

eqString

Signature

export declare const eqString: Eq<string>

Added in v2.0.0

getMonoid

Signature

export declare function getMonoid<A>(): Monoid<Eq<A>>

Added in v2.6.0

getStructEq

Signature

export declare function getStructEq<O extends ReadonlyRecord<string, any>>(eqs: { [K in keyof O]: Eq<O[K]> }): Eq<O>

Added in v2.0.0

getTupleEq

Given a tuple of Eqs returns a Eq for the tuple

Signature

export declare function getTupleEq<T extends ReadonlyArray<Eq<any>>>(
  ...eqs: T
): Eq<{ [K in keyof T]: T[K] extends Eq<infer A> ? A : never }>

Example

import { getTupleEq, eqString, eqNumber, eqBoolean } from 'fp-ts/lib/Eq'

const E = getTupleEq(eqString, eqNumber, eqBoolean)
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)

Added in v2.0.0

type classes

Eq (interface)

Signature

export interface Eq<A> {
  readonly equals: (x: A, y: A) => boolean
}

Added in v2.0.0

utils

strictEqual

Use eqStrict instead

Signature

export declare function strictEqual<A>(a: A, b: A): boolean

Added in v2.0.0