Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

premap

import { premap } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/comparable.ts";

Create a Comparable using a Comparable and a function that takes a type L and returns a type D.

@example
import { premap, number } from "./comparable.ts";
import { pipe } from "./fn.ts";

const dateToNumber = (d: Date): number => d.valueOf();
const date = pipe(number, premap(dateToNumber));

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

Another use for premap with eq is to check for equality after normalizing data. In the following we can compare strings ignoring case by normalizing to lowercase strings.

@example
import { premap, string } from "./comparable.ts";
import { pipe } from "./fn.ts";

const lowercase = (s: string) => s.toLowerCase();
const insensitive = pipe(
  string, // exact string compare
  premap(lowercase), // makes all strings lowercase
);

const result1 = insensitive.compare("Hello")("World"); // false
const result2 = insensitive.compare("hello")("Hello"); // true
function premap<L, D>(fld: (l: L) => D): (eq: Comparable<D>) => Comparable<L>;
§
premap<L, D>(fld: (l: L) => D): (eq: Comparable<D>) => Comparable<L>
[src]

§Type Parameters

§Parameters

§
fld: (l: L) => D
[src]

§Return Type