Skip to main content
Module

x/fun/mod.ts>eq.union

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Go to Latest
function eq.union
import { eq } from "https://deno.land/x/fun@v2.0.0-alpha.6/mod.ts";
const { union } = eq;

Create a eq from two other eqs. The resultant eq checks that any two values are equal according to at least one of the supplied eqs.

It should be noted that we cannot differentiate the eq used to compare two disparate types like number and number[]. Thus, internally union must type cast to any and treat thrown errors as a false equivalence. To mitigate most of these issues we first test if the 'typeof' the values matches, but keep in mind that if you are doing any nonsense by mutating within a eq that union will find and expose such nonsense in inconsistent ways.

Examples

Example 1

import { union, number, string } from "./eq.ts";
import { pipe } from "./fn.ts";

const { equals } = pipe(number, union(string));

const result1 = equals(1)("Hello"); // false
const result2 = equals(1)(1); // true

Returns

<A>(first: Eq<A>) => Eq<A | I>