Skip to main content
Module

x/fun/mod.ts>decoder.annotate

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

Annotate the DecodeError output of an existing Decoder if it fails while parsing. Internally, this uses the DecodeError Wrap constructor.

Examples

Example 1

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

const decoder = pipe(
  D.literal("a", "b", "c", 1, 2, 3),
  D.annotate("like the song"),
);

const result1 = decoder(1); // Right(1)
const result2 = D.unwrap(decoder("d"));
// Left(`like the song
// └─ cannot decode "d", should be "a", "b", "c", 1, 2, 3`)

Parameters

context: string

Returns

<D, A>(decoder: Decoder<D, A>) => Decoder<D, A>