Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fun/mod.ts>decoder.premap

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

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>