Skip to main content
Module

x/fun/comparable.ts>method

A collection of algebraic data types, lenses, and schemables based on a light weight higher kinded type implementation. Written for deno.
Latest
function method
import { method } from "https://deno.land/x/fun@v2.0.0/comparable.ts";

Create a eq from a method on a class or prototypical object. This exists because many objects in javascript do now allow you to pass an object method around on its own without its parent object. For example, if you pass Date.valueOf (type () => number) into another function and call it, the call will fail because valueOf does not carry the reference of its parent object around.

Examples

Example 1

import { method, number } from "./comparable.ts";

// This eq will work for date, but also for any objects that have
// a valueOf method that returns a number.
const date = method("valueOf", number);

const now = new Date();
const alsoNow = new Date(Date.now());
const later = new Date(Date.now() + 60 * 60 * 1000);

const result1 = date.compare(now)(alsoNow); // true
const result2 = date.compare(now)(later); // false

Type Parameters

M extends string
A

Parameters

method: M
unnamed 1: Comparable<A>

Returns

Comparable<readonly [K in M]: () => A>