Skip to main content
Module

x/fun/decoder.ts>premap

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

Map over the input of a Decoder contravariantly. This allows one to use an existing decoder against a transformed input.

Examples

Example 1

import * as D from "./decoder.ts";
import { pipe } from "./fn.ts";

const fromStr = pipe(
  D.tuple(D.string, D.string),
  D.premap((s) => [s, s] as const),
);

const result1 = fromStr("hello"); // Right(["hello", "hello"])
const result2 = fromStr(null); // Left(DecodeError)

Parameters

fld: (l: L) => D

Returns

<A>(ua: Decoder<D, A>) => Decoder<L, A>