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
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)